1 /*
2  * Copyright (C) 2018 Rafael Ostertag
3  *
4  * This file is part of YAPET.
5  *
6  * YAPET is free software: you can redistribute it and/or modify it under the
7  * terms of the GNU General Public License as published by the Free Software
8  * Foundation, either version 3 of the License, or (at your option) any later
9  * version.
10  *
11  * YAPET is distributed in the hope that it will be useful, but WITHOUT ANY
12  * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
13  * FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
14  * details.
15  *
16  * You should have received a copy of the GNU General Public License along with
17  * YAPET.  If not, see <http://www.gnu.org/licenses/>.
18  *
19  * Additional permission under GNU GPL version 3 section 7
20  *
21  * If you modify this program, or any covered work, by linking or combining it
22  * with the OpenSSL project's OpenSSL library (or a modified version of that
23  * library), containing parts covered by the terms of the OpenSSL or SSLeay
24  * licenses, Rafael Ostertag grants you additional permission to convey the
25  * resulting work.  Corresponding Source for a non-source form of such a
26  * combination shall include the source code for the parts of OpenSSL used as
27  * well as that of the covered work.
28  */
29 
30 #ifdef HAVE_CONFIG_H
31 #include "config.h"
32 #endif
33 
34 #ifdef HAVE_LIBGEN_H
35 #include <libgen.h>
36 #endif
37 
38 #include <cstdlib>
39 #include <cstring>
40 
41 #include "globals.h"
42 #include "intl.h"
43 #include "yapetlockscreen.h"
44 
45 //
46 // Public
47 //
48 
YapetLockScreen(YACURS::Window & mainWindow,YACURS::UnlockDialog * _unlock,unsigned int timeout,unsigned int ulck_timeout)49 YapetLockScreen::YapetLockScreen(YACURS::Window& mainWindow,
50                                  YACURS::UnlockDialog* _unlock,
51                                  unsigned int timeout,
52                                  unsigned int ulck_timeout)
53     : LockScreen{_unlock, timeout, ulck_timeout},
54       _mainWindow{dynamic_cast<const MainWindow&>(mainWindow)} {}
55 
~YapetLockScreen()56 YapetLockScreen::~YapetLockScreen() {}
57 
show()58 void YapetLockScreen::show() {
59     if (_mainWindow.currentFilename().empty()) {
60         // we cannot lock, there is no open file
61         return;
62     }
63 
64     LockScreen::show();
65 
66     YACURS::Curses::set_terminal_title(_("YAPET LOCKED"));
67 }
68 
close()69 void YapetLockScreen::close() {
70     LockScreen::close();
71 
72     if (!_mainWindow.currentFilename().empty()) {
73         std::string ttl("YAPET");
74 #ifdef HAVE_BASENAME
75         ttl += " (";
76         // basename may modify the string
77         char* tmp = strdup(_mainWindow.currentFilename().c_str());
78         ttl += basename(tmp);
79 
80         ttl += ")";
81         std::free(tmp);
82 #endif
83         YACURS::Curses::set_terminal_title(ttl);
84     }
85 }
86