From 699befe618d5f1dd76872b9002c8e4d68baa4e76 Mon Sep 17 00:00:00 2001 From: sniperbeamer Date: Tue, 30 Sep 2008 19:03:41 +0000 Subject: [PATCH] Added "Tools" button to EditEntryDlg: Window List and Auto-Type sequence git-svn-id: https://svn.code.sf.net/p/keepassx/code/trunk@228 b624d157-de02-0410-bad0-e51aec6abb33 --- src/dialogs/EditEntryDlg.cpp | 56 +++++++++++++++++++----------- src/dialogs/EditEntryDlg.h | 10 +++--- src/dialogs/PasswordGenDlg.cpp | 1 - src/dialogs/TargetWindowDlg.cpp | 37 ++++++++++++++++++++ src/dialogs/TargetWindowDlg.h | 40 ++++++++++++++++++++++ src/forms/TargetWindowDlg.ui | 42 +++++++++++++++++++++++ src/lib/AutoType.h | 2 ++ src/lib/AutoType_X11.cpp | 60 ++++++++++++++++++++++++++++++++- src/main.cpp | 3 ++ src/src.pro | 6 ++-- 10 files changed, 227 insertions(+), 30 deletions(-) create mode 100644 src/dialogs/TargetWindowDlg.cpp create mode 100644 src/dialogs/TargetWindowDlg.h create mode 100644 src/forms/TargetWindowDlg.ui diff --git a/src/dialogs/EditEntryDlg.cpp b/src/dialogs/EditEntryDlg.cpp index 3da7204..0f344c9 100644 --- a/src/dialogs/EditEntryDlg.cpp +++ b/src/dialogs/EditEntryDlg.cpp @@ -23,7 +23,7 @@ #include "PasswordGenDlg.h" #include "EditEntryDlg.h" #include "CalendarDlg.h" - +#include "TargetWindowDlg.h" CEditEntryDlg::CEditEntryDlg(IDatabase* _db, IEntryHandle* _entry,QWidget* parent, bool modal, bool newEntry) : QDialog(parent) @@ -107,10 +107,6 @@ CEditEntryDlg::CEditEntryDlg(IDatabase* _db, IEntryHandle* _entry,QWidget* paren Edit_Comment->setPlainText(entry->comment()); InitGroupComboBox(); -/* MX-TO-DO: After approval, remove this invokation - InitIconComboBox(); -*/ - if(!entry->binarySize()){ ButtonSaveAttachment->setDisabled(true); ButtonDeleteAttachment->setDisabled(true); @@ -126,12 +122,22 @@ CEditEntryDlg::CEditEntryDlg(IDatabase* _db, IEntryHandle* _entry,QWidget* paren else{ DateTime_Expire->setDateTime(entry->expire()); } + +#ifdef AUTOTYPE + QToolButton* buttonTools = new QToolButton(buttonBox); + buttonTools->setText("Tools"); + buttonTools->setPopupMode(QToolButton::InstantPopup); + QMenu* menuTools = new QMenu(buttonTools); + connect(menuTools->addAction("Auto-Type: Customize Sequence"), SIGNAL(triggered(bool)), SLOT(OnCustomizeSequence())); +#ifdef GLOBAL_AUTOTYPE + connect(menuTools->addAction("Auto-Type: Select target window"), SIGNAL(triggered(bool)), SLOT(OnSelectTarget())); +#endif + buttonTools->setMenu(menuTools); + buttonBox->addButton(buttonTools, QDialogButtonBox::ResetRole); // ResetRole: workaround to display button on the left +#endif } -CEditEntryDlg::~CEditEntryDlg() -{ - - +CEditEntryDlg::~CEditEntryDlg(){ } void CEditEntryDlg::resizeEvent(QResizeEvent *event){ @@ -148,16 +154,6 @@ void CEditEntryDlg::paintEvent(QPaintEvent *event){ painter.drawPixmap(QPoint(0,0),BannerPixmap); } -/* MX-TO-DO: After approval, remove this implementation - -void CEditEntryDlg::InitIconComboBox(){ - for(int i=0;inumIcons();i++){ - Combo_IconPicker->insertItem(i,db->icon(i),""); - } - Combo_IconPicker->setCurrentIndex(entry->image()); -} -*/ - void CEditEntryDlg::InitGroupComboBox(){ QString Space; groups=db->sortedGroups(); @@ -433,3 +429,25 @@ void CEditEntryDlg::OnCalendar(QAction* action){ void CEditEntryDlg::OnClose(){ config->setDialogGeometry(this); } + + +void CEditEntryDlg::OnCustomizeSequence(){ +#ifdef AUTOTYPE + QString text = Edit_Comment->toPlainText(); + if (!text.isEmpty()) + text.append("\n"); + Edit_Comment->setPlainText(text.append("Auto-Type: {USERNAME}{TAB}{PASSWORD}{ENTER}")); +#endif +} + +void CEditEntryDlg::OnSelectTarget(){ +#ifdef GLOBAL_AUTOTYPE + TargetWindowDlg dlg(this); + if (dlg.exec() && !dlg.windowTitle().isEmpty()){ + QString text = Edit_Comment->toPlainText(); + if (!text.isEmpty()) + text.append("\n"); + Edit_Comment->setPlainText(text.append(dlg.windowTitle())); + } +#endif +} diff --git a/src/dialogs/EditEntryDlg.h b/src/dialogs/EditEntryDlg.h index 26ae5a2..ef09d80 100644 --- a/src/dialogs/EditEntryDlg.h +++ b/src/dialogs/EditEntryDlg.h @@ -31,9 +31,6 @@ class CEditEntryDlg : public QDialog, private Ui_EditEntryDialog CEditEntryDlg(IDatabase* _db, IEntryHandle* _entry,QWidget* parent = 0, bool modal = FALSE, bool newEntry = FALSE); ~CEditEntryDlg(); void InitGroupComboBox(); -/* MX-TO-DO: Remove this declaration - void InitIconComboBox(); -*/ static void saveAttachment(IEntryHandle* pEntry, QWidget* ParentWidget=NULL); IEntryHandle* entry; @@ -60,14 +57,15 @@ class CEditEntryDlg : public QDialog, private Ui_EditEntryDialog void OnExpirePreset(QAction* action); void OnCalendar(QAction* action); void OnClose(); + void OnCustomizeSequence(); + void OnSelectTarget(); - private: + private: virtual void paintEvent(QPaintEvent*); virtual void resizeEvent(QResizeEvent *); - + int IconIndex; bool pNewEntry; }; #endif - diff --git a/src/dialogs/PasswordGenDlg.cpp b/src/dialogs/PasswordGenDlg.cpp index 6ce4987..7f5d9da 100644 --- a/src/dialogs/PasswordGenDlg.cpp +++ b/src/dialogs/PasswordGenDlg.cpp @@ -448,7 +448,6 @@ void CGenPwDialog::generatePasswordInternal(char* buffer, int length){ } } else{ - qDebug("ja"); for (int i=0; iaddItem(*i); + + connect(buttonBox, SIGNAL(accepted()), SLOT(OnAccept())); + connect(buttonBox, SIGNAL(rejected()), SLOT(reject())); +} + +void TargetWindowDlg::OnAccept(){ + pWindowTitle = comboWindow->itemText(comboWindow->currentIndex()); + accept(); +} diff --git a/src/dialogs/TargetWindowDlg.h b/src/dialogs/TargetWindowDlg.h new file mode 100644 index 0000000..5146630 --- /dev/null +++ b/src/dialogs/TargetWindowDlg.h @@ -0,0 +1,40 @@ +/*************************************************************************** + * Copyright (C) 2008 by Felix Geyer * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; version 2 of the License. * + * * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the * + * Free Software Foundation, Inc., * + * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * + ***************************************************************************/ + +#ifndef TARGETWINDOWDLG_H +#define TARGETWINDOWDLG_H + +#include "ui_TargetWindowDlg.h" + +class TargetWindowDlg : public QDialog, private Ui_TargetWindowDlg +{ + Q_OBJECT + + public: + TargetWindowDlg(QWidget* parent); + inline QString windowTitle() { return pWindowTitle; }; + + private slots: + void OnAccept(); + + private: + QString pWindowTitle; +}; + +#endif // TARGETWINDOWDLG_H diff --git a/src/forms/TargetWindowDlg.ui b/src/forms/TargetWindowDlg.ui new file mode 100644 index 0000000..f3a68c1 --- /dev/null +++ b/src/forms/TargetWindowDlg.ui @@ -0,0 +1,42 @@ + + TargetWindowDlg + + + + 0 + 0 + 574 + 145 + + + + Auto-Type: Select Target Window + + + + + + To specify the target window, either select an existing currently-opened window +from the drop-down list, or enter the window title manually: + + + + + + + true + + + + + + + QDialogButtonBox::Cancel|QDialogButtonBox::Ok + + + + + + + + diff --git a/src/lib/AutoType.h b/src/lib/AutoType.h index 1a7d47d..1f2a84e 100644 --- a/src/lib/AutoType.h +++ b/src/lib/AutoType.h @@ -40,6 +40,8 @@ class AutoType{ static void performGlobal(); static bool registerGlobalShortcut(const Shortcut& s); static void unregisterGlobalShortcut(); + static void init(); + static QStringList getAllWindowTitles(); #endif // GLOBAL_AUTOTYPE }; #endif // AUTOTYPE diff --git a/src/lib/AutoType_X11.cpp b/src/lib/AutoType_X11.cpp index 01d56bd..6573b01 100644 --- a/src/lib/AutoType_X11.cpp +++ b/src/lib/AutoType_X11.cpp @@ -159,6 +159,64 @@ void AutoType::perform(IEntryHandle* entry, QString& err,bool hideWindow,int nr) } #ifdef GLOBAL_AUTOTYPE + +Window windowRoot; +QStringList windowBlacklist; +Atom wm_state; + +void windowTitles(Window window, QStringList& titleList){ + Display* d = QX11Info::display(); + + Atom type = None; + int format; + unsigned long nitems, after; + unsigned char* data; + XGetWindowProperty(d, window, wm_state, 0, 0, false, AnyPropertyType, &type, &format, &nitems, &after, &data); + if (type){ + XTextProperty textProp; + if (XGetWMName(d, window, &textProp) != 0) { + char** list = NULL; + int count; + if (Xutf8TextPropertyToTextList(d, &textProp, &list, &count)>=0 && list){ + QString title = QString::fromUtf8(list[0]); + if (window!=windowRoot && window!=AutoType::MainWin->winId() && + (QApplication::activeWindow()==NULL || window!=QApplication::activeWindow()->winId()) && + !windowBlacklist.contains(title) + ){ + titleList.append(title); + } + XFreeStringList(list); + } + } + } + + Window root; + Window parent; + Window* children = NULL; + unsigned int num_children; + int tree = XQueryTree(d, window, &root, &parent, &children, &num_children); + if (tree && children){ + for (int i=0; ix11Info().screen()); + windowBlacklist << "kicker" << "KDE Desktop"; +} + +QStringList AutoType::getAllWindowTitles(){ + QStringList titleList; + if (wm_state) // don't do anything if WM_STATE doesn't exist + windowTitles(windowRoot, titleList); + return titleList; +} + void AutoType::performGlobal(){ if (MainWin->isLocked()) MainWin->OnUnLockWorkspace(); @@ -277,7 +335,7 @@ bool AutoType::registerGlobalShortcut(const Shortcut& s){ return true; Display* display = QX11Info::display(); - Window root = XDefaultRootWindow(display); + Window root = XRootWindow(display, MainWin->x11Info().screen()); int code=XKeysymToKeycode(display, HelperX11::getKeysym(s.key)); int mod=HelperX11::getShortcutModifierMask(s); diff --git a/src/main.cpp b/src/main.cpp index d997ea3..0036c9d 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -195,6 +195,9 @@ int main(int argc, char **argv) QApplication::setQuitOnLastWindowClosed(false); KeepassMainWindow *mainWin = new KeepassMainWindow(args.file(), args.startMinimized(), args.startLocked()); +#ifdef GLOBAL_AUTOTYPE + AutoType::init(); +#endif int r=app->exec(); delete mainWin; delete eventListener; diff --git a/src/src.pro b/src/src.pro index aefd8aa..0079b15 100644 --- a/src/src.pro +++ b/src/src.pro @@ -112,9 +112,9 @@ isEqual(QMAKE_WIN32,1){ INSTALLS += target data contains(DEFINES,GLOBAL_AUTOTYPE){ - FORMS += forms/AutoTypeDlg.ui - HEADERS += dialogs/AutoTypeDlg.h lib/AutoTypeTreeWidget.h - SOURCES += dialogs/AutoTypeDlg.cpp lib/AutoTypeTreeWidget.cpp + FORMS += forms/AutoTypeDlg.ui forms/TargetWindowDlg.ui + HEADERS += dialogs/AutoTypeDlg.h lib/AutoTypeTreeWidget.h dialogs/TargetWindowDlg.h + SOURCES += dialogs/AutoTypeDlg.cpp lib/AutoTypeTreeWidget.cpp dialogs/TargetWindowDlg.cpp }