📜 ⬆️ ⬇️

Helping KeePassX to work with Indicator Applet Complete in the latest Ubuntu versions

After the news about the stolen password database on LinkedIn, I thought about the security of my passwords.

Began to look for the password manager for Ubuntu 12.04, stopped at KeePassX. It completely suited me if it were not for one little thing: in Ubuntu 12.04 I use Gnome Classic, and Indicator Applet Complete for clocks / systray. And this applet draws a menu by clicking on the program icon with the left mouse button, and when you click on the right, it draws its menus. And if KeePassX is minimized to a tray, then there is no way to restore it from there.

I tried to solve the problem in several ways: I tried to write on the forum, I found the same bug that had been hanging since 2011, but it seems that the author threw all his strength on KeePassX 2, and abandoned the first version.
')
Well, am I a trembling creature, or do I have the right programmer? I decided to fix the problem myself, namely, by adding a new item to the Systray menu, that is, so that you can show the main window from the systray menu.

I’ll warn you right now that many people won’t be interested in the article, this is my first experience with Qt, and I wrote the last time in C / C ++ last year in 1999, and I remember only basic things. Article decided to write, because This is my first successful experience of modifying OpenSource programs on Qt, maybe someone will need it.

UPD It turned out I invented the bike. This is all due to the sni-qt package, which redesigns QSystemTrayIcon into StatusNotifierItems. After removing the package, the icon got to another tray, where the click works as it should. Thank you inkvizitor68sl for the comment.

If still interesting, welcome under cat.


Project Setup


We download source codes here , we unpack. We will continue to work in the source folder.

Install the necessary libraries, and Qt Creator at the same time
$ sudo apt-get install build-essential qt4-qmake libxtst-dev qtcreator 

Make sure all libraries are in place:
 $ qmake && make 

If everything is in order, the project will be compiled and you can run the program from the bin directory.

We start Qt Creator (I have it in Applications / Programming), open the project keepassx.pro



You can also enable debugging; in KeePassX, it is enabled through explicitly setting a variable in src.pro:


We check that the project is configured correctly: Build -> Build All, then the Run button.

Add a menu item


Qt uses an event model when components publish certain events (called Action), and you can subscribe to these events.

To begin, add a new event. Open the form MainWindow.ui, then in the Action Editor tab add a new event


We save, and then the first surprise that took me a couple of hours: Qt Creator adds gag to the form code. So you need to double-click on the element of the table (in which the list of passwords for the current group is displayed, on the form at the top right) and remove the "1" column.

Next you need to add this Action to the menu. Open mainwindow.cpp, go to the very end of the setupMenus method and change the code as follows:
 SysTrayMenu = new QMenu(APP_DISPLAY_NAME,this); SysTrayMenu->addAction(ShowHideAction); //     ,        ShowHideAction SysTrayMenu->addAction(FileUnLockWorkspaceAction); SysTrayMenu->addSeparator(); SysTrayMenu->addAction(FileExitAction); SysTray->setContextMenu(SysTrayMenu); 

Now it's time to write a method that will be called when you click on our menu item.
Without unnecessary problems, we write at the end of mainwindow.cpp
 void KeepassMainWindow::OnShowHide(){ OnSysTrayActivated(QSystemTrayIcon::Trigger); } 

That is, we simply call an existing method that should work when clicking on the tray icon, but does not work.

Do not forget about the headers: change mainwindow.h, add the line to private slots
 void OnShowHide(); 

And finally, now you need to associate the ShowHideAction event with the OnShowHide method. Add to the end of the setupConnections () method
 connect(ShowHideAction,SIGNAL(triggered()), this, SLOT(OnShowHide())); 


Save everything and try to run. If done correctly, a new item should appear in the menu.


Install and build the package


Now it's time to install the new version in the system. We go to the terminal, just in case, we will recompile in the same way as we did at the beginning of the article, and then we execute
 sudo checkinstall 

Checkinstall will ask you a couple of questions, you can leave everything at default, but I recommend changing the version to something like 0.4.3-1 to prevent rollback to the old version when updating packages.

Everything, when the command is completed, you will receive the installed KeePassX and at the same time .deb package, which can be installed on another machine.

Sources are available here: github.com/relgames/keepassx

Source: https://habr.com/ru/post/146507/


All Articles