diff options
-rwxr-xr-x | fileencryptiondialog.cpp | 10 | ||||
-rw-r--r-- | gpg4usb.pro | 6 | ||||
-rw-r--r-- | gpgwin.cpp | 7 | ||||
-rwxr-xr-x | keymgmt.cpp | 4 | ||||
-rwxr-xr-x | keymgmt.h | 2 | ||||
-rwxr-xr-x | quitdialog.cpp | 128 | ||||
-rwxr-xr-x | quitdialog.h | 61 | ||||
-rwxr-xr-x | release/icons/error.png | bin | 0 -> 3080 bytes | |||
-rw-r--r-- | textedit.cpp | 77 | ||||
-rw-r--r-- | textedit.h | 10 |
10 files changed, 272 insertions, 33 deletions
diff --git a/fileencryptiondialog.cpp b/fileencryptiondialog.cpp index 931aaa3..41c2639 100755 --- a/fileencryptiondialog.cpp +++ b/fileencryptiondialog.cpp @@ -21,16 +21,13 @@ #include <QWidget> #include <QDialogButtonBox> -#include <QGroupBox> -#include <QLineEdit> #include <QLabel> #include <QPushButton> -#include <QGridLayout> -#include <QRadioButton> #include <QHBoxLayout> #include <QVBoxLayout> -#include <QFileDialog> #include <QDebug> +#include <QFileDialog> +#include <QRadioButton> #include "fileencryptiondialog.h" @@ -76,7 +73,8 @@ FileEncryptionDialog::FileEncryptionDialog(GpgME::Context *ctx, QString iconPath mKeyList->hide(); mKeyList->setColumnWidth(2, 150); mKeyList->setColumnWidth(3, 150); - mKeyList->setChecked(&keyList); + mKeyList->setChecked(&keyList); + /* Setup Action */ radioEnc = new QRadioButton(tr("&Encrypt")); connect(radioEnc, SIGNAL(clicked()), this, SLOT(showKeyList())); diff --git a/gpg4usb.pro b/gpg4usb.pro index 25265f1..0ab3204 100644 --- a/gpg4usb.pro +++ b/gpg4usb.pro @@ -27,7 +27,8 @@ HEADERS += attachments.h \ settingsdialog.h \ attachmenttablemodel.h \ textedit.h \ - editorpage.h + editorpage.h \ + quitdialog.h SOURCES += attachments.cpp \ context.cpp \ gpgwin.cpp \ @@ -41,7 +42,8 @@ SOURCES += attachments.cpp \ settingsdialog.cpp \ attachmenttablemodel.cpp \ textedit.cpp \ - editorpage.cpp + editorpage.cpp \ + quitdialog.cpp RC_FILE = gpg4usb.rc # comment out line below for static building @@ -36,7 +36,7 @@ GpgWin::GpgWin() setCorner(Qt::BottomLeftCorner, Qt::LeftDockWidgetArea); setCorner(Qt::BottomRightCorner, Qt::RightDockWidgetArea); - edit = new TextEdit(); + edit = new TextEdit(iconPath); setCentralWidget(edit); /* the list of Keys available*/ @@ -298,12 +298,12 @@ void GpgWin::createActions() switchTabUpAct = new QAction(this); switchTabUpAct->setShortcut(QKeySequence(Qt::CTRL + Qt::Key_Tab)); connect(switchTabUpAct, SIGNAL(triggered()), edit, SLOT(switchTabUp())); - this->addAction(switchTabUpAct); + //this->addAction(switchTabUpAct); switchTabDownAct = new QAction(this); switchTabDownAct->setShortcut(QKeySequence(Qt::CTRL + Qt::Key_Shift+ Qt::Key_Tab)); connect(switchTabDownAct, SIGNAL(triggered()), edit, SLOT(switchTabDown())); - this->addAction(switchTabDownAct); + //this->addAction(switchTabDownAct); } void GpgWin::createMenus() @@ -424,7 +424,6 @@ void GpgWin::createDockWindows() void GpgWin::closeEvent(QCloseEvent *event) { - /** * ask to save changes, if there are * modified documents in any tab diff --git a/keymgmt.cpp b/keymgmt.cpp index 2cf21c0..6cb2a05 100755 --- a/keymgmt.cpp +++ b/keymgmt.cpp @@ -25,10 +25,10 @@ #include "keymgmt.h" -KeyMgmt::KeyMgmt(GpgME::Context *ctx, QString iconpath) +KeyMgmt::KeyMgmt(GpgME::Context *ctx, QString iconPath) { mCtx = ctx; - mIconPath = iconpath; + mIconPath = iconPath; /* the list of Keys available*/ mKeyList = new KeyList(mCtx, mIconPath); @@ -46,7 +46,7 @@ class KeyMgmt : public QMainWindow Q_OBJECT public: - KeyMgmt(GpgME::Context* ctx, QString iconpath); + KeyMgmt(GpgME::Context* ctx, QString iconPath); public slots: void importKeyFromFile(); diff --git a/quitdialog.cpp b/quitdialog.cpp new file mode 100755 index 0000000..e599f6b --- /dev/null +++ b/quitdialog.cpp @@ -0,0 +1,128 @@ +/* + * + * keymgmt.cpp + * + * Copyright 2008 gpg4usb-team <[email protected]> + * + * 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; either version 2 of the License, or + * (at your option) any later version. + * + * 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., 51 Franklin Street, Fifth Floor, Boston, + * MA 02110-1301, USA. + */ + +#include <QtGui> +#include <QTableWidget> +#include "quitdialog.h" +class QMessageBox; + +QuitDialog::QuitDialog(QWidget *parent, QHash<int, QString> unsavedDocs, QString iconPath) + : QDialog(parent) +{ + setWindowTitle(tr("Unsaved files")); + setModal(true); + discarded =false; + + /* + * Table of unsaved documents + */ + QHashIterator<int, QString> i (unsavedDocs); + int row = 0; + mFileList = new QTableWidget(this); + mFileList->horizontalHeader()->hide(); + mFileList->setColumnCount(3); + mFileList->setColumnWidth(0, 20); + mFileList->setColumnHidden(2, true); + mFileList->verticalHeader()->hide(); + mFileList->setShowGrid(false); + mFileList->setEditTriggers(QAbstractItemView::NoEditTriggers); + mFileList->setFocusPolicy(Qt::NoFocus); + mFileList->horizontalHeader()->setStretchLastSection( true ); + + // fill the table + while (i.hasNext()) { + i.next(); + mFileList->setRowCount(mFileList->rowCount()+1); + + // checkbox in front of filename + QTableWidgetItem *tmp0 = new QTableWidgetItem(); + tmp0->setFlags(Qt::ItemIsUserCheckable | Qt::ItemIsEnabled ); + tmp0->setCheckState(Qt::Checked); + mFileList->setItem(row, 0, tmp0); + + // filename + QTableWidgetItem *tmp1 = new QTableWidgetItem(i.value()); + mFileList->setItem(row, 1, tmp1); + + // tab-index in hidden column + QTableWidgetItem *tmp2 = new QTableWidgetItem(QString::number(i.key())); + mFileList->setItem(row, 2, tmp2); + qDebug() << "tmp2:" << tmp2->text(); + ++row; + } + /* + * Warnbox with icon and text + */ + QPixmap *pixmap = new QPixmap(iconPath + "error.png"); + QLabel *warnicon = new QLabel(); + warnicon->setPixmap(*pixmap); + QLabel *warnlabel = new QLabel(tr("%1 files contain unsaved information.").arg(row)+"\n"+tr("Save the changes before closing?")); + QHBoxLayout *warnBoxLayout = new QHBoxLayout(); + warnBoxLayout->addWidget(warnicon); + warnBoxLayout->addWidget(warnlabel); + warnBoxLayout->setAlignment(Qt::AlignLeft); + QWidget *warnBox = new QWidget(this); + warnBox->setLayout(warnBoxLayout); + + QLabel *checkLabel = new QLabel(tr("Check the files you want to save")); + + QLabel *notelabel = new QLabel(tr("NOTE: If you don't save these files, all changes are lost.")+"\n"); + + QDialogButtonBox *buttonBox = new QDialogButtonBox(QDialogButtonBox::Discard |QDialogButtonBox::Save | QDialogButtonBox::Cancel); + connect(buttonBox, SIGNAL(accepted()), this, SLOT(accept())); + connect(buttonBox, SIGNAL(rejected()), this, SLOT(reject())); + QPushButton* btnNoKey = buttonBox->button(QDialogButtonBox::Discard); + connect(btnNoKey, SIGNAL(clicked()), SLOT(myDiscard())); + QVBoxLayout *vbox = new QVBoxLayout(); + vbox->addWidget(warnBox); + vbox->addWidget(checkLabel); + vbox->addWidget(mFileList); + vbox->addWidget(notelabel); + vbox->addWidget(buttonBox); + this->setLayout(vbox); + +} + + +void QuitDialog::myDiscard() +{ + discarded =true; + reject(); +} + +bool QuitDialog::isDiscarded() +{ + return discarded; +} + +QList <int> QuitDialog::getTabIdsToSave() +{ + QList <int> tabIdsToSave; + for (int i = 0; i < mFileList->rowCount(); i++) { + if (mFileList->item(i, 0)->checkState() == Qt::Checked) { + qDebug() << mFileList->item(i, 2)->text(); + tabIdsToSave << mFileList->item(i, 2)->text().toInt(); + } + } + return tabIdsToSave; +} + diff --git a/quitdialog.h b/quitdialog.h new file mode 100755 index 0000000..0dd4bf5 --- /dev/null +++ b/quitdialog.h @@ -0,0 +1,61 @@ +/* + * keymgmt.h + * + * Copyright 2008 gpg4usb-team <[email protected]> + * + * 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; either version 2 of the License, or + * (at your option) any later version. + * + * 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., 51 Franklin Street, Fifth Floor, Boston, + * MA 02110-1301, USA. + */ + +#ifndef __QUITDIALOG_H__ +#define __QUITDIALOG_H__ + + +class QMainWindow; +class QWidget; +class iostream; +class QtGui; +class QString; +class QFileDialog; +class QStringList; +class QIcon; +class QAction; +class QMenu; +class QApplication; +class QProgresssBar; + +#include "keygenthread.h" +#include "context.h" +class QuitDialog : public QDialog +{ + Q_OBJECT + +public: + QuitDialog(QWidget *parent,QHash<int, QString> unsavedDocs, QString iconPath); + bool isDiscarded(); + QList <int> getTabIdsToSave(); + +private slots: +// void accept(); + void myDiscard(); + +private: + QAction *closeAct; + QLabel *nameLabel; + bool discarded; + QTableWidget *mFileList; +}; + +#endif // __QUITDIALOG_H__ diff --git a/release/icons/error.png b/release/icons/error.png Binary files differnew file mode 100755 index 0000000..d64c533 --- /dev/null +++ b/release/icons/error.png diff --git a/textedit.cpp b/textedit.cpp index 84a2622..084da83 100644 --- a/textedit.cpp +++ b/textedit.cpp @@ -22,12 +22,13 @@ #include "QDebug" #include "QUrl" #include "textedit.h" - +#include "quitdialog.h" class QFileDialog; class QMessageBox; -TextEdit::TextEdit() +TextEdit::TextEdit(QString iconPath) { + mIconPath = iconPath; countPage = 0; tabWidget = new QTabWidget(this); tabWidget->setMovable(true); @@ -304,7 +305,6 @@ bool TextEdit::maybeSaveCurrentTab() { { QString filePath = page->getFilePath(); QMessageBox::StandardButton result; - result = QMessageBox::warning(this, tr("Unsaved document"), tr("The document has been modified:")+"\n"+filePath+"\n\n"+tr("Do you want to save your changes?"), QMessageBox::Save | QMessageBox::Discard | QMessageBox::Cancel); @@ -324,8 +324,18 @@ bool TextEdit::maybeSaveCurrentTab() { return true; } +bool TextEdit::saveTab(int i) { + EditorPage *page = qobject_cast<EditorPage *> (tabWidget->widget(i)); + + QString filePath = page->getFilePath(); + if (filePath == "") { + return saveAs(); + } else { + return saveFile(filePath); + } + - +} /** * Checks if there are unsaved documents in any tab, * which may need to be saved. Call this function before @@ -361,7 +371,7 @@ bool TextEdit::maybeSaveAnyTab() /* * more than one unsaved documents */ - } else if(unsavedDocs.size() > 0) { + } else if(unsavedDocs.size() > 1) { QString docList; QHashIterator<int, QString> i (unsavedDocs); @@ -371,19 +381,29 @@ bool TextEdit::maybeSaveAnyTab() docList.append(i.value()).append("\n"); } - QMessageBox::StandardButton result; - result = QMessageBox::warning(this, tr("Unsaved documents"), - tr("There are unsaved changes in the following documents:\n") - + docList, - QMessageBox::Discard | QMessageBox::Cancel); + QuitDialog *dialog; + dialog=new QuitDialog(this, unsavedDocs, mIconPath); - if (result == QMessageBox::Discard) { - return true; + + int result = dialog->exec(); + // return true, if app can be closed + if (result == QDialog::Rejected){ + if (dialog->isDiscarded()){ + return true; + } else { + return false; + } } else { - return false; + QList <int> tabIdsToSave = dialog->getTabIdsToSave(); + foreach (int tabId, tabIdsToSave){ + qDebug() << "handling for save" << tabId; + + } + + return true; } - /* + /* * no unsaved documents */ } else { @@ -414,7 +434,6 @@ void TextEdit::dragEnterEvent(QDragEnterEvent *event) { if (event->mimeData()->hasFormat("text/plain")) qDebug() << "enter textedit drag action"; - event->acceptProposedAction(); } @@ -503,6 +522,7 @@ void TextEdit::showModified() { } void TextEdit::switchTabUp() { + qDebug() << "hallo"; if (tabWidget->count() > 1) { if (tabWidget->count() == tabWidget->currentIndex()+1){ @@ -516,6 +536,7 @@ void TextEdit::switchTabUp() { } void TextEdit::switchTabDown() { + qDebug() << "hallo"; if (tabWidget->count() > 1) { if (tabWidget->currentIndex()==1) { @@ -526,5 +547,31 @@ void TextEdit::switchTabDown() { tabWidget->setCurrentIndex(tabWidget->currentIndex()-1); } } + this->removeTab(0);; +} + +int TextEdit::getUnsavedDocumentsNumber() { + int number=0; + for(int i=0; i < tabWidget->count(); i++) { + EditorPage *ep = qobject_cast<EditorPage *> (tabWidget->widget(i)); + if(ep->getTextPage()->document()->isModified()) { + number++; + } + } + return number; } +QHash<int, QString> TextEdit::unsavedDocuments() { + QHash<int, QString> unsavedDocs; // this list could be used to implement gedit like "unsaved changed"-dialog + + for(int i=0; i < tabWidget->count(); i++) { + EditorPage *ep = qobject_cast<EditorPage *> (tabWidget->widget(i)); + if(ep->getTextPage()->document()->isModified()) { + QString docname = tabWidget->tabText(i); + // remove * before name of modified doc + docname.remove(0,2); + unsavedDocs.insert(i, docname); + } + } + return unsavedDocs; +} @@ -40,11 +40,13 @@ class TextEdit : public QWidget { Q_OBJECT public: - TextEdit(); + TextEdit(QString iconPath); void loadFile(const QString &fileName); bool maybeSaveAnyTab(); bool maybeSaveCurrentTab(); QPlainTextEdit* curTextPage(); + int getUnsavedDocumentsNumber(); + QHash<int, QString> unsavedDocuments(); public slots: void quote(); @@ -60,11 +62,13 @@ public slots: private: QString strippedName(const QString &fullFileName); - int countPage; - QTabWidget *tabWidget; bool maybeSaveFile(); EditorPage *curPage(); void setCursorPosition(); + QString mIconPath; + int countPage; + QTabWidget *tabWidget; + bool saveTab(int i); private slots: void removeTab(int index); |