git-svn-id: https://svn.code.sf.net/p/keepassx/code/trunk@146 b624d157-de02-0410-bad0-e51aec6abb33master
After Width: | Height: | Size: 6.0 KiB |
After Width: | Height: | Size: 2.3 KiB |
After Width: | Height: | Size: 2.6 KiB |
After Width: | Height: | Size: 2.3 KiB |
After Width: | Height: | Size: 1.4 KiB |
After Width: | Height: | Size: 1.7 KiB |
After Width: | Height: | Size: 1.8 KiB |
@ -0,0 +1,58 @@ |
||||
/***************************************************************************
|
||||
* Copyright (C) 2007 by Tarek Saidi * |
||||
* tarek.saidi@arcor.de * |
||||
* * |
||||
* 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 <QFileInfo> |
||||
#include "AddBookmarkDlg.h" |
||||
#include "lib/FileDialogs.h" |
||||
#include "lib/bookmarks.h" |
||||
|
||||
AddBookmarkDlg::AddBookmarkDlg(QWidget* parent, QString DefaultFilename, int _ItemID):QDialog(parent) |
||||
{ |
||||
setupUi(this); |
||||
ItemID=_ItemID; |
||||
connect(Button_Browse,SIGNAL(clicked()),this,SLOT(OnButtonBrowse())); |
||||
connect(buttonBox->button(QDialogButtonBox::Ok),SIGNAL(clicked()),this,SLOT(OnButtonOk())); |
||||
connect(buttonBox->button(QDialogButtonBox::Cancel),SIGNAL(clicked()),this,SLOT(reject())); |
||||
if(ItemID==-1){ |
||||
if(DefaultFilename==QString()) |
||||
OnButtonBrowse(); |
||||
else |
||||
Edit_Filename->setText(DefaultFilename); |
||||
} |
||||
else { |
||||
Edit_Title->setText(KpxBookmarks::title(ItemID)); |
||||
Edit_Filename->setText(KpxBookmarks::path(ItemID)); |
||||
setWindowTitle(tr("Edit Bookmark")); |
||||
} |
||||
} |
||||
|
||||
void AddBookmarkDlg::OnButtonBrowse(){ |
||||
QString path=KpxFileDialogs::openExistingFile(this,"AddBookmarkDlg", tr("Add Bookmark"), |
||||
QStringList() << tr("KeePass Databases (*.kdb)") << tr("All Files (*)")); |
||||
if(path!=QString()) |
||||
Edit_Filename->setText(path); |
||||
} |
||||
|
||||
void AddBookmarkDlg::OnButtonOk(){ |
||||
if(ItemID==-1) |
||||
ItemID=KpxBookmarks::add(Edit_Title->text(),Edit_Filename->text()); |
||||
else |
||||
KpxBookmarks::edit(Edit_Title->text(),Edit_Filename->text(),ItemID); |
||||
accept();
|
||||
} |
@ -0,0 +1,41 @@ |
||||
/***************************************************************************
|
||||
* Copyright (C) 2007 by Tarek Saidi * |
||||
* tarek.saidi@arcor.de * |
||||
* * |
||||
* 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 _ADDBOOKMARKDLG_H_ |
||||
#define _ADDBOOKMARKDLG_H_ |
||||
|
||||
#include <QDialog> |
||||
#include "ui_AddBookmarkDlg.h" |
||||
|
||||
class AddBookmarkDlg : public QDialog, private Ui::AddBookmarkDlg |
||||
{ |
||||
Q_OBJECT |
||||
|
||||
public: |
||||
AddBookmarkDlg (QWidget* parent=0, QString DefaultFilename=QString(), int ItemID=-1); |
||||
int ItemID; |
||||
|
||||
private slots: |
||||
void OnButtonOk(); |
||||
void OnButtonBrowse(); |
||||
|
||||
}; |
||||
|
||||
#endif |
||||
|
@ -0,0 +1,117 @@ |
||||
/***************************************************************************
|
||||
* Copyright (C) 2007 by Tarek Saidi * |
||||
* tarek.saidi@arcor.de * |
||||
* * |
||||
* 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 <QListWidget> |
||||
#include "main.h" |
||||
#include "ManageBookmarksDlg.h" |
||||
#include "lib/bookmarks.h" |
||||
#include "dialogs/AddBookmarkDlg.h" |
||||
|
||||
ManageBookmarksDlg::ManageBookmarksDlg(QWidget* parent):QDialog(parent) |
||||
{ |
||||
setupUi(this); |
||||
for(int i=0;i<KpxBookmarks::count();i++){ |
||||
QListWidgetItem* item=new QListWidgetItem(ListWidget); |
||||
item->setData(Qt::UserRole,i); |
||||
item->setText(KpxBookmarks::title(i));
|
||||
} |
||||
connect(Button_Up,SIGNAL(clicked()),this,SLOT(OnButtonUp())); |
||||
connect(Button_Down,SIGNAL(clicked()),this,SLOT(OnButtonDown())); |
||||
connect(Button_Delete,SIGNAL(clicked()),this,SLOT(OnButtonDelete())); |
||||
connect(Button_Add,SIGNAL(clicked()),this,SLOT(OnButtonAdd())); |
||||
connect(Button_Edit,SIGNAL(clicked()),this,SLOT(OnButtonEdit())); |
||||
connect(ListWidget,SIGNAL(itemDoubleClicked(QListWidgetItem*)),this,SLOT(edit(QListWidgetItem*))); |
||||
connect(buttonBox->button(QDialogButtonBox::Close),SIGNAL(clicked()),this,SLOT(close())); |
||||
|
||||
Button_Up->setIcon(getIcon("up")); |
||||
Button_Down->setIcon(getIcon("down")); |
||||
Button_Delete->setIcon(getIcon("delete")); |
||||
Button_Edit->setIcon(getIcon("bookmark_edit")); |
||||
Button_Add->setIcon(getIcon("bookmark_add")); |
||||
} |
||||
|
||||
|
||||
void ManageBookmarksDlg::OnButtonUp(){ |
||||
int row=ListWidget->currentRow(); |
||||
QListWidgetItem* item=ListWidget->currentItem(); |
||||
if(row==-1 || !item || row==0)return; |
||||
ListWidget->takeItem(row); |
||||
row--; |
||||
ListWidget->insertItem(row,item); |
||||
ListWidget->setCurrentRow(row); |
||||
} |
||||
|
||||
void ManageBookmarksDlg::OnButtonDown(){ |
||||
int row=ListWidget->currentRow(); |
||||
QListWidgetItem* item=ListWidget->currentItem(); |
||||
if(row==-1 || !item || row==ListWidget->count()-1)return; |
||||
ListWidget->takeItem(row); |
||||
row++; |
||||
ListWidget->insertItem(row,item); |
||||
ListWidget->setCurrentRow(row); |
||||
} |
||||
|
||||
void ManageBookmarksDlg::OnButtonDelete(){ |
||||
QListWidgetItem* item=ListWidget->currentItem(); |
||||
if(!item)return; |
||||
int index=item->data(Qt::UserRole).toInt(); |
||||
KpxBookmarks::remove(index); |
||||
delete item; |
||||
for(int i=0;i<ListWidget->count();i++){ |
||||
int itemindex=ListWidget->item(i)->data(Qt::UserRole).toInt(); |
||||
if(itemindex>index) |
||||
ListWidget->item(i)->setData(Qt::UserRole,itemindex-1); |
||||
} |
||||
} |
||||
|
||||
void ManageBookmarksDlg::OnButtonEdit(){ |
||||
QListWidgetItem* item=ListWidget->currentItem(); |
||||
if(!item)return; |
||||
edit(item);
|
||||
} |
||||
|
||||
void ManageBookmarksDlg::edit(QListWidgetItem* item){ |
||||
int i=item->data(Qt::UserRole).toInt(); |
||||
AddBookmarkDlg dlg(this,QString(),i); |
||||
dlg.exec();
|
||||
item->setText(KpxBookmarks::title(i));
|
||||
} |
||||
|
||||
|
||||
void ManageBookmarksDlg::OnButtonAdd(){ |
||||
AddBookmarkDlg dlg(this); |
||||
if(dlg.exec()){ |
||||
int i=dlg.ItemID; |
||||
QListWidgetItem* item=new QListWidgetItem(ListWidget); |
||||
item->setData(Qt::UserRole,i); |
||||
item->setText(KpxBookmarks::title(i));
|
||||
} |
||||
return; |
||||
} |
||||
|
||||
void ManageBookmarksDlg::closeEvent(QCloseEvent * event){ |
||||
QList<int> Order; |
||||
// Creating a list with the new indices
|
||||
// Order[OldIndex]==NewIndex
|
||||
for(int i=0;i<KpxBookmarks::count();i++){ |
||||
Order<<ListWidget->item(i)->data(Qt::UserRole).toInt(); |
||||
} |
||||
KpxBookmarks::resort(Order);
|
||||
event->accept(); |
||||
} |
@ -0,0 +1,44 @@ |
||||
/***************************************************************************
|
||||
* Copyright (C) 2007 by Tarek Saidi * |
||||
* tarek.saidi@arcor.de * |
||||
* * |
||||
* 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 MANAGEBOOKMARKSDLG_H |
||||
#define MANAGEBOOKMARKSDLG_H |
||||
|
||||
#include <QDialog> |
||||
#include <QCloseEvent> |
||||
#include "ui_ManageBookmarksDlg.h" |
||||
|
||||
class ManageBookmarksDlg : public QDialog, private Ui::ManageBookmarksDlg |
||||
{ |
||||
Q_OBJECT |
||||
public: |
||||
ManageBookmarksDlg(QWidget* parent=0); |
||||
private: |
||||
virtual void closeEvent(QCloseEvent* event); |
||||
private slots: |
||||
void OnButtonUp(); |
||||
void OnButtonDown(); |
||||
void OnButtonDelete(); |
||||
void OnButtonAdd(); |
||||
void OnButtonEdit(); |
||||
void edit(QListWidgetItem*); |
||||
}; |
||||
|
||||
#endif |
||||
|
@ -0,0 +1,58 @@ |
||||
<ui version="4.0" > |
||||
<class>AddBookmarkDlg</class> |
||||
<widget class="QWidget" name="AddBookmarkDlg" > |
||||
<property name="geometry" > |
||||
<rect> |
||||
<x>0</x> |
||||
<y>0</y> |
||||
<width>497</width> |
||||
<height>148</height> |
||||
</rect> |
||||
</property> |
||||
<property name="windowTitle" > |
||||
<string>Add Bookmark</string> |
||||
</property> |
||||
<layout class="QVBoxLayout" > |
||||
<item> |
||||
<layout class="QGridLayout" > |
||||
<item row="0" column="0" > |
||||
<widget class="QLabel" name="label" > |
||||
<property name="text" > |
||||
<string>Title:</string> |
||||
</property> |
||||
</widget> |
||||
</item> |
||||
<item row="0" column="1" > |
||||
<widget class="QLineEdit" name="Edit_Title" /> |
||||
</item> |
||||
<item row="1" column="0" > |
||||
<widget class="QLabel" name="label_2" > |
||||
<property name="text" > |
||||
<string>File:</string> |
||||
</property> |
||||
</widget> |
||||
</item> |
||||
<item row="1" column="1" > |
||||
<widget class="QLineEdit" name="Edit_Filename" /> |
||||
</item> |
||||
<item row="1" column="2" > |
||||
<widget class="QPushButton" name="Button_Browse" > |
||||
<property name="text" > |
||||
<string>Browse...</string> |
||||
</property> |
||||
</widget> |
||||
</item> |
||||
</layout> |
||||
</item> |
||||
<item> |
||||
<widget class="QDialogButtonBox" name="buttonBox" > |
||||
<property name="standardButtons" > |
||||
<set>QDialogButtonBox::Cancel|QDialogButtonBox::NoButton|QDialogButtonBox::Ok</set> |
||||
</property> |
||||
</widget> |
||||
</item> |
||||
</layout> |
||||
</widget> |
||||
<resources/> |
||||
<connections/> |
||||
</ui> |
@ -0,0 +1,69 @@ |
||||
<ui version="4.0" > |
||||
<class>ManageBookmarksDlg</class> |
||||
<widget class="QDialog" name="ManageBookmarksDlg" > |
||||
<property name="geometry" > |
||||
<rect> |
||||
<x>0</x> |
||||
<y>0</y> |
||||
<width>452</width> |
||||
<height>360</height> |
||||
</rect> |
||||
</property> |
||||
<property name="windowTitle" > |
||||
<string>Manage Bookmarks</string> |
||||
</property> |
||||
<layout class="QVBoxLayout" > |
||||
<item> |
||||
<layout class="QHBoxLayout" > |
||||
<item> |
||||
<widget class="QListWidget" name="ListWidget" /> |
||||
</item> |
||||
<item> |
||||
<layout class="QVBoxLayout" > |
||||
<item> |
||||
<widget class="QToolButton" name="Button_Add" /> |
||||
</item> |
||||
<item> |
||||
<widget class="QToolButton" name="Button_Delete" /> |
||||
</item> |
||||
<item> |
||||
<widget class="QToolButton" name="Button_Edit" /> |
||||
</item> |
||||
<item> |
||||
<widget class="QToolButton" name="Button_Up" /> |
||||
</item> |
||||
<item> |
||||
<widget class="QToolButton" name="Button_Down" /> |
||||
</item> |
||||
<item> |
||||
<spacer> |
||||
<property name="orientation" > |
||||
<enum>Qt::Vertical</enum> |
||||
</property> |
||||
<property name="sizeHint" > |
||||
<size> |
||||
<width>20</width> |
||||
<height>161</height> |
||||
</size> |
||||
</property> |
||||
</spacer> |
||||
</item> |
||||
</layout> |
||||
</item> |
||||
</layout> |
||||
</item> |
||||
<item> |
||||
<widget class="QDialogButtonBox" name="buttonBox" > |
||||
<property name="orientation" > |
||||
<enum>Qt::Horizontal</enum> |
||||
</property> |
||||
<property name="standardButtons" > |
||||
<set>QDialogButtonBox::Close</set> |
||||
</property> |
||||
</widget> |
||||
</item> |
||||
</layout> |
||||
</widget> |
||||
<resources/> |
||||
<connections/> |
||||
</ui> |
@ -0,0 +1,127 @@ |
||||
/***************************************************************************
|
||||
* Copyright (C) 2007 by Tarek Saidi * |
||||
* tarek.saidi@arcor.de * |
||||
* * |
||||
* 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 <QFile> |
||||
#include "bookmarks.h" |
||||
#include "main.h" |
||||
#define CSTR(x)(x.toUtf8().data()) |
||||
|
||||
QList<KpxBookmarks::BookmarkEntry> KpxBookmarks::Bookmarks; |
||||
QString KpxBookmarks::filename; |
||||
|
||||
bool KpxBookmarks::load(const QString& _filename){ |
||||
/*
|
||||
Fileformat: |
||||
"Title1" "Path1"\n |
||||
"Title2" "Path2"\n |
||||
...
|
||||
*/ |
||||
|
||||
filename=_filename; |
||||
QFile file(filename); |
||||
if(!file.exists()){ |
||||
return true; |
||||
} |
||||
if(!file.open(QIODevice::ReadOnly)){ |
||||
qWarning("Reading bookmarks failed: %s",CSTR(decodeFileError(file.error()))); |
||||
return false;
|
||||
} |
||||
QString content=QString::fromUtf8(file.readAll()); |
||||
file.close(); |
||||
content.replace("\r",""); |
||||
QStringList lines=content.split("\n"); |
||||
for(int i=0;i<lines.size();i++){ |
||||
if(lines[i].simplified()==QString()) continue; //skip empty line
|
||||
if(lines[i].count("\"")!=4){ |
||||
qWarning("Bookmark parsing error: Skipping line %i.",i); |
||||
continue;
|
||||
} |
||||
int a_title=lines[i].indexOf("\""); |
||||
int b_title=lines[i].indexOf("\"",a_title+1); |
||||
int a_path=lines[i].indexOf("\"",b_title+1); |
||||
int b_path=lines[i].indexOf("\"",a_path+1); |
||||
BookmarkEntry entry; |
||||
entry.Title=lines[i].mid(a_title+1,b_title-a_title-1); |
||||
entry.Path=lines[i].mid(a_path+1,b_path-a_path-1); |
||||
Bookmarks << entry; |
||||
} |
||||
return true;
|
||||
} |
||||
|
||||
int KpxBookmarks::count(){ |
||||
return Bookmarks.size(); |
||||
} |
||||
|
||||
QString KpxBookmarks::title(int i){ |
||||
return Bookmarks[i].Title; |
||||
} |
||||
|
||||
QString KpxBookmarks::path(int i){ |
||||
return Bookmarks[i].Path; |
||||
} |
||||
|
||||
|
||||
int KpxBookmarks::add(const QString& Title,const QString& Path){ |
||||
BookmarkEntry entry; |
||||
entry.Title=Title; |
||||
entry.Path=Path; |
||||
entry.Index=Bookmarks.size(); |
||||
Bookmarks<<entry; |
||||
save(); |
||||
return Bookmarks.size()-1; |
||||
} |
||||
|
||||
bool KpxBookmarks::save(){ |
||||
QFile file(filename); |
||||
if(!file.exists()){ |
||||
return false; |
||||
} |
||||
if(!file.open(QIODevice::WriteOnly | QIODevice::Truncate)){ |
||||
qWarning("Writing bookmarks failed: %s",CSTR(decodeFileError(file.error()))); |
||||
return false;
|
||||
} |
||||
QString data; |
||||
for(int i=0;i<Bookmarks.size();i++){ |
||||
data+=QString("\"%1\" \"%2\"\n").arg(Bookmarks[i].Title) |
||||
.arg(Bookmarks[i].Path);
|
||||
} |
||||
file.write(data.toUtf8()); |
||||
file.close();
|
||||
} |
||||
|
||||
void KpxBookmarks::remove(int index){ |
||||
Bookmarks.removeAt(index); |
||||
save(); |
||||
} |
||||
|
||||
void KpxBookmarks::edit(const QString& Title,const QString& Path,int i){ |
||||
Bookmarks[i].Title=Title; |
||||
Bookmarks[i].Path=Path; |
||||
save(); |
||||
} |
||||
|
||||
|
||||
void KpxBookmarks::resort(QList<int> order){ |
||||
QList<BookmarkEntry> NewList; |
||||
for(int i=0;i<order.size();i++){ |
||||
NewList << Bookmarks[order[i]];
|
||||
} |
||||
Bookmarks=NewList; |
||||
save(); |
||||
} |
@ -0,0 +1,49 @@ |
||||
/***************************************************************************
|
||||
* Copyright (C) 2007 by Tarek Saidi * |
||||
* tarek.saidi@arcor.de * |
||||
* * |
||||
* 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 _BOOKMARKS_H_ |
||||
#define _BOOKMARKS_H_ |
||||
|
||||
#include <QString> |
||||
#include <QList> |
||||
|
||||
class KpxBookmarks {
|
||||
public: |
||||
static bool load(const QString& file); |
||||
static int add(const QString& Title,const QString& Path); |
||||
static void remove(int id); |
||||
static void edit(const QString& Title,const QString& Path, int Index); |
||||
static int count(); |
||||
static void resort(QList<int> order); |
||||
static QString title(int Index); |
||||
static QString path(int Index); |
||||
private: |
||||
static bool save(); |
||||
class BookmarkEntry { |
||||
public: |
||||
QString Title; |
||||
QString Path; |
||||
int Index;
|
||||
}; |
||||
static QList<BookmarkEntry> Bookmarks; |
||||
static QString filename; |
||||
|
||||
}; |
||||
|
||||
|
||||
#endif |