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
master
sniperbeamer 16 years ago
parent a5d427d262
commit 699befe618
  1. 56
      src/dialogs/EditEntryDlg.cpp
  2. 10
      src/dialogs/EditEntryDlg.h
  3. 1
      src/dialogs/PasswordGenDlg.cpp
  4. 37
      src/dialogs/TargetWindowDlg.cpp
  5. 40
      src/dialogs/TargetWindowDlg.h
  6. 42
      src/forms/TargetWindowDlg.ui
  7. 2
      src/lib/AutoType.h
  8. 60
      src/lib/AutoType_X11.cpp
  9. 3
      src/main.cpp
  10. 6
      src/src.pro

@ -23,7 +23,7 @@
#include "PasswordGenDlg.h" #include "PasswordGenDlg.h"
#include "EditEntryDlg.h" #include "EditEntryDlg.h"
#include "CalendarDlg.h" #include "CalendarDlg.h"
#include "TargetWindowDlg.h"
CEditEntryDlg::CEditEntryDlg(IDatabase* _db, IEntryHandle* _entry,QWidget* parent, bool modal, bool newEntry) CEditEntryDlg::CEditEntryDlg(IDatabase* _db, IEntryHandle* _entry,QWidget* parent, bool modal, bool newEntry)
: QDialog(parent) : QDialog(parent)
@ -107,10 +107,6 @@ CEditEntryDlg::CEditEntryDlg(IDatabase* _db, IEntryHandle* _entry,QWidget* paren
Edit_Comment->setPlainText(entry->comment()); Edit_Comment->setPlainText(entry->comment());
InitGroupComboBox(); InitGroupComboBox();
/* MX-TO-DO: After approval, remove this invokation
InitIconComboBox();
*/
if(!entry->binarySize()){ if(!entry->binarySize()){
ButtonSaveAttachment->setDisabled(true); ButtonSaveAttachment->setDisabled(true);
ButtonDeleteAttachment->setDisabled(true); ButtonDeleteAttachment->setDisabled(true);
@ -126,12 +122,22 @@ CEditEntryDlg::CEditEntryDlg(IDatabase* _db, IEntryHandle* _entry,QWidget* paren
else{ else{
DateTime_Expire->setDateTime(entry->expire()); 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){ void CEditEntryDlg::resizeEvent(QResizeEvent *event){
@ -148,16 +154,6 @@ void CEditEntryDlg::paintEvent(QPaintEvent *event){
painter.drawPixmap(QPoint(0,0),BannerPixmap); painter.drawPixmap(QPoint(0,0),BannerPixmap);
} }
/* MX-TO-DO: After approval, remove this implementation
void CEditEntryDlg::InitIconComboBox(){
for(int i=0;i<db->numIcons();i++){
Combo_IconPicker->insertItem(i,db->icon(i),"");
}
Combo_IconPicker->setCurrentIndex(entry->image());
}
*/
void CEditEntryDlg::InitGroupComboBox(){ void CEditEntryDlg::InitGroupComboBox(){
QString Space; QString Space;
groups=db->sortedGroups(); groups=db->sortedGroups();
@ -433,3 +429,25 @@ void CEditEntryDlg::OnCalendar(QAction* action){
void CEditEntryDlg::OnClose(){ void CEditEntryDlg::OnClose(){
config->setDialogGeometry(this); 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
}

@ -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(IDatabase* _db, IEntryHandle* _entry,QWidget* parent = 0, bool modal = FALSE, bool newEntry = FALSE);
~CEditEntryDlg(); ~CEditEntryDlg();
void InitGroupComboBox(); void InitGroupComboBox();
/* MX-TO-DO: Remove this declaration
void InitIconComboBox();
*/
static void saveAttachment(IEntryHandle* pEntry, QWidget* ParentWidget=NULL); static void saveAttachment(IEntryHandle* pEntry, QWidget* ParentWidget=NULL);
IEntryHandle* entry; IEntryHandle* entry;
@ -60,14 +57,15 @@ class CEditEntryDlg : public QDialog, private Ui_EditEntryDialog
void OnExpirePreset(QAction* action); void OnExpirePreset(QAction* action);
void OnCalendar(QAction* action); void OnCalendar(QAction* action);
void OnClose(); void OnClose();
void OnCustomizeSequence();
void OnSelectTarget();
private: private:
virtual void paintEvent(QPaintEvent*); virtual void paintEvent(QPaintEvent*);
virtual void resizeEvent(QResizeEvent *); virtual void resizeEvent(QResizeEvent *);
int IconIndex; int IconIndex;
bool pNewEntry; bool pNewEntry;
}; };
#endif #endif

@ -448,7 +448,6 @@ void CGenPwDialog::generatePasswordInternal(char* buffer, int length){
} }
} }
else{ else{
qDebug("ja");
for (int i=0; i<length; i++) for (int i=0; i<length; i++)
buffer[i] = assoctable[randint(num)]; buffer[i] = assoctable[randint(num)];
} }

@ -0,0 +1,37 @@
/***************************************************************************
* 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. *
***************************************************************************/
#include "TargetWindowDlg.h"
#include "AutoType.h"
TargetWindowDlg::TargetWindowDlg(QWidget* parent) : QDialog(parent){
setupUi(this);
QStringList windowTitles = AutoType::getAllWindowTitles();
windowTitles.sort();
for (QStringList::const_iterator i = windowTitles.constBegin(); i != windowTitles.constEnd(); ++i)
comboWindow->addItem(*i);
connect(buttonBox, SIGNAL(accepted()), SLOT(OnAccept()));
connect(buttonBox, SIGNAL(rejected()), SLOT(reject()));
}
void TargetWindowDlg::OnAccept(){
pWindowTitle = comboWindow->itemText(comboWindow->currentIndex());
accept();
}

@ -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

@ -0,0 +1,42 @@
<ui version="4.0" >
<class>TargetWindowDlg</class>
<widget class="QDialog" name="TargetWindowDlg" >
<property name="geometry" >
<rect>
<x>0</x>
<y>0</y>
<width>574</width>
<height>145</height>
</rect>
</property>
<property name="windowTitle" >
<string>Auto-Type: Select Target Window</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout" >
<item>
<widget class="QLabel" name="label" >
<property name="text" >
<string>To specify the target window, either select an existing currently-opened window
from the drop-down list, or enter the window title manually:</string>
</property>
</widget>
</item>
<item>
<widget class="QComboBox" name="comboWindow" >
<property name="editable" >
<bool>true</bool>
</property>
</widget>
</item>
<item>
<widget class="QDialogButtonBox" name="buttonBox" >
<property name="standardButtons" >
<set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
</property>
</widget>
</item>
</layout>
</widget>
<resources/>
<connections/>
</ui>

@ -40,6 +40,8 @@ class AutoType{
static void performGlobal(); static void performGlobal();
static bool registerGlobalShortcut(const Shortcut& s); static bool registerGlobalShortcut(const Shortcut& s);
static void unregisterGlobalShortcut(); static void unregisterGlobalShortcut();
static void init();
static QStringList getAllWindowTitles();
#endif // GLOBAL_AUTOTYPE #endif // GLOBAL_AUTOTYPE
}; };
#endif // AUTOTYPE #endif // AUTOTYPE

@ -159,6 +159,64 @@ void AutoType::perform(IEntryHandle* entry, QString& err,bool hideWindow,int nr)
} }
#ifdef GLOBAL_AUTOTYPE #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; i<num_children; i++)
windowTitles(children[i], titleList);
}
else
XFree(children);
}
void AutoType::init(){
Display* d = QX11Info::display();
wm_state = XInternAtom(d, "WM_STATE", true);
windowRoot = XRootWindow(d, MainWin->x11Info().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(){ void AutoType::performGlobal(){
if (MainWin->isLocked()) if (MainWin->isLocked())
MainWin->OnUnLockWorkspace(); MainWin->OnUnLockWorkspace();
@ -277,7 +335,7 @@ bool AutoType::registerGlobalShortcut(const Shortcut& s){
return true; return true;
Display* display = QX11Info::display(); Display* display = QX11Info::display();
Window root = XDefaultRootWindow(display); Window root = XRootWindow(display, MainWin->x11Info().screen());
int code=XKeysymToKeycode(display, HelperX11::getKeysym(s.key)); int code=XKeysymToKeycode(display, HelperX11::getKeysym(s.key));
int mod=HelperX11::getShortcutModifierMask(s); int mod=HelperX11::getShortcutModifierMask(s);

@ -195,6 +195,9 @@ int main(int argc, char **argv)
QApplication::setQuitOnLastWindowClosed(false); QApplication::setQuitOnLastWindowClosed(false);
KeepassMainWindow *mainWin = new KeepassMainWindow(args.file(), args.startMinimized(), args.startLocked()); KeepassMainWindow *mainWin = new KeepassMainWindow(args.file(), args.startMinimized(), args.startLocked());
#ifdef GLOBAL_AUTOTYPE
AutoType::init();
#endif
int r=app->exec(); int r=app->exec();
delete mainWin; delete mainWin;
delete eventListener; delete eventListener;

@ -112,9 +112,9 @@ isEqual(QMAKE_WIN32,1){
INSTALLS += target data INSTALLS += target data
contains(DEFINES,GLOBAL_AUTOTYPE){ contains(DEFINES,GLOBAL_AUTOTYPE){
FORMS += forms/AutoTypeDlg.ui FORMS += forms/AutoTypeDlg.ui forms/TargetWindowDlg.ui
HEADERS += dialogs/AutoTypeDlg.h lib/AutoTypeTreeWidget.h HEADERS += dialogs/AutoTypeDlg.h lib/AutoTypeTreeWidget.h dialogs/TargetWindowDlg.h
SOURCES += dialogs/AutoTypeDlg.cpp lib/AutoTypeTreeWidget.cpp SOURCES += dialogs/AutoTypeDlg.cpp lib/AutoTypeTreeWidget.cpp dialogs/TargetWindowDlg.cpp
} }