diff options
author | nils <nils@34ebc366-c3a9-4b3c-9f84-69acf7962910> | 2011-01-01 17:47:22 +0000 |
---|---|---|
committer | nils <nils@34ebc366-c3a9-4b3c-9f84-69acf7962910> | 2011-01-01 17:47:22 +0000 |
commit | 458cc9d49f929cfd4826c9e5c8a83ec90fd7efa0 (patch) | |
tree | 0de3f96f0cea53fd49e1e6f273ccb4992d785d62 | |
parent | comment out sign/verify for now (diff) | |
download | gpg4usb-458cc9d49f929cfd4826c9e5c8a83ec90fd7efa0.tar.gz gpg4usb-458cc9d49f929cfd4826c9e5c8a83ec90fd7efa0.zip |
moved open,save,saveas and print slots to textedit-class
git-svn-id: http://cpunk.de/svn/src/gpg4usb/trunk@416 34ebc366-c3a9-4b3c-9f84-69acf7962910
-rw-r--r-- | gpgwin.cpp | 130 | ||||
-rw-r--r-- | gpgwin.h | 9 | ||||
-rw-r--r-- | keylist.h | 1 | ||||
-rw-r--r-- | textedit.cpp | 118 | ||||
-rw-r--r-- | textedit.h | 26 |
5 files changed, 145 insertions, 139 deletions
@@ -55,7 +55,7 @@ GpgWin::GpgWin() createToolBars(); createStatusBar(); createDockWindows(); - setCurrentFile(""); + edit->setCurrentFile(""); mKeyList->addMenuAction(appendSelectedKeysAct); restoreSettings(); @@ -65,7 +65,7 @@ GpgWin::GpgWin() if (args.size() > 1) { if (!args[1].startsWith("-")) { if (QFile::exists(args[1])) - loadFile(args[1]); + edit->loadFile(args[1]); } } } @@ -129,25 +129,25 @@ void GpgWin::createActions() openAct->setIcon(QIcon(iconPath + "fileopen.png")); openAct->setShortcut(QKeySequence::Open); openAct->setToolTip(tr("Open an existing file")); - connect(openAct, SIGNAL(triggered()), this, SLOT(open())); + connect(openAct, SIGNAL(triggered()), edit, SLOT(open())); saveAct = new QAction(tr("&Save"), this); saveAct->setIcon(QIcon(iconPath + "filesave.png")); saveAct->setShortcut(QKeySequence::Save); saveAct->setToolTip(tr("Save the current File")); - connect(saveAct, SIGNAL(triggered()), this, SLOT(save())); + connect(saveAct, SIGNAL(triggered()), edit, SLOT(save())); saveAsAct = new QAction(tr("Save &As"), this); saveAsAct->setIcon(QIcon(iconPath + "filesaveas.png")); saveAsAct->setShortcut(QKeySequence::SaveAs); saveAsAct->setToolTip(tr("Save the current File as...")); - connect(saveAsAct, SIGNAL(triggered()), this, SLOT(saveAs())); + connect(saveAsAct, SIGNAL(triggered()), edit, SLOT(saveAs())); printAct = new QAction(tr("&Print"), this); printAct->setIcon(QIcon(iconPath + "fileprint.png")); printAct->setShortcut(QKeySequence::Print); printAct->setToolTip(tr("Print Document")); - connect(printAct, SIGNAL(triggered()), this, SLOT(print())); + connect(printAct, SIGNAL(triggered()), edit, SLOT(print())); quitAct = new QAction(tr("&Quit"), this); // quitAct->setShortcut(QKeySequence::Quit); @@ -397,7 +397,7 @@ void GpgWin::closeEvent(QCloseEvent *event) { /** ask to save changes, if text modified */ - if (maybeSave()) { + if (edit->maybeSave()) { saveSettings(); event->accept(); } else { @@ -409,122 +409,6 @@ void GpgWin::closeEvent(QCloseEvent *event) } -void GpgWin::open() -{ - if (maybeSave()) { - QString fileName = QFileDialog::getOpenFileName(this); - if (!fileName.isEmpty()) - loadFile(fileName); - } -} - -bool GpgWin::save() -{ - if (curFile.isEmpty()) { - return saveAs(); - } else { - return saveFile(curFile); - } -} - -bool GpgWin::saveAs() -{ - QString fileName = QFileDialog::getSaveFileName(this); - if (fileName.isEmpty()) - return false; - - return saveFile(fileName); -} - -void GpgWin::loadFile(const QString &fileName) -{ - QFile file(fileName); - if (!file.open(QFile::ReadOnly | QFile::Text)) { - QMessageBox::warning(this, tr("Application"), - tr("Cannot read file %1:\n%2.") - .arg(fileName) - .arg(file.errorString())); - return; - } - - QTextStream in(&file); - QApplication::setOverrideCursor(Qt::WaitCursor); - edit->setPlainText(in.readAll()); - QApplication::restoreOverrideCursor(); - - setCurrentFile(fileName); - statusBar()->showMessage(tr("File loaded"), 2000); -} - -void GpgWin::setCurrentFile(const QString &fileName) -{ - curFile = fileName; - edit->document()->setModified(false); - setWindowModified(false); - - QString shownName; - if (curFile.isEmpty()) - shownName = "untitled.txt"; - else - shownName = strippedName(curFile); - - setWindowTitle(tr("%1[*] - %2").arg(shownName).arg(qApp->applicationName())); -} - -QString GpgWin::strippedName(const QString &fullFileName) -{ - return QFileInfo(fullFileName).fileName(); -} - -bool GpgWin::maybeSave() -{ - if (edit->document()->isModified()) { - QMessageBox::StandardButton ret; - ret = QMessageBox::warning(this, tr("Application"), - tr("The document has been modified.\nDo you want to save your changes?"), - QMessageBox::Save | QMessageBox::Discard | QMessageBox::Cancel); - if (ret == QMessageBox::Save) - return save(); - else if (ret == QMessageBox::Cancel) - return false; - } - return true; -} - -bool GpgWin::saveFile(const QString &fileName) -{ - QFile file(fileName); - if (!file.open(QFile::WriteOnly | QFile::Text)) { - QMessageBox::warning(this, tr("File"), - tr("Cannot write file %1:\n%2.") - .arg(fileName) - .arg(file.errorString())); - return false; - } - QTextStream out(&file); - QApplication::setOverrideCursor(Qt::WaitCursor); - out << edit->toPlainText(); - QApplication::restoreOverrideCursor(); - statusBar()->showMessage(tr("Saved '%1'").arg(fileName), 2000); - return true; -} - -void GpgWin::print() -{ -#ifndef QT_NO_PRINTER - QTextDocument *document = edit->document(); - QPrinter printer; - - QPrintDialog *dlg = new QPrintDialog(&printer, this); - if (dlg->exec() != QDialog::Accepted) - return; - - document->print(&printer); - - statusBar()->showMessage(tr("Ready"), 2000); -#endif -} - void GpgWin::about() { QMessageBox::about(this, tr("About ") + qApp->applicationName(), @@ -73,11 +73,7 @@ public slots: //void deleteSelectedKeys(); void appendSelectedKeys(); void openKeyManagement(); - void print(); void about(); - bool save(); - bool saveAs(); - void open(); void fileEncryption(); void openSettingsDialog(); void openTutorial(); @@ -92,15 +88,10 @@ private: void createToolBars(); void createStatusBar(); void createDockWindows(); - bool saveFile(const QString &fileName); - void loadFile(const QString &fileName); - void setCurrentFile(const QString &fileName); - bool maybeSave(); void restoreSettings(); void saveSettings(); void preventNoDataErr(QByteArray *in); void parseMime(QByteArray *message); - QString strippedName(const QString &fullFileName); TextEdit *edit; QMenu *fileMenu; @@ -29,7 +29,6 @@ class QVBoxLayout; class QTableWidgetItem; class QLabel; class QMessageBox; -class QtGui; class QTableWidget; class QPushButton; class QMenu; diff --git a/textedit.cpp b/textedit.cpp index 202c3e8..ae9bebe 100644 --- a/textedit.cpp +++ b/textedit.cpp @@ -1,6 +1,8 @@ #include "QDebug" #include "QUrl" -class QString; +class QFileDialog; +class QMessageBox; + #include "textedit.h" TextEdit::TextEdit(QWidget *parent) { @@ -53,3 +55,117 @@ bool TextEdit::isKey(QString key) qDebug() << key.contains("-----BEGIN PGP PUBLIC KEY BLOCK-----", Qt::CaseSensitive); return true; } + +void TextEdit::open() +{ + if (maybeSave()) { + QString fileName = QFileDialog::getOpenFileName(this); + if (!fileName.isEmpty()) + loadFile(fileName); + } +} + +bool TextEdit::save() +{ + if (curFile.isEmpty()) { + return saveAs(); + } else { + return saveFile(curFile); + } +} + +bool TextEdit::saveAs() +{ + QString fileName = QFileDialog::getSaveFileName(this); + if (fileName.isEmpty()) + return false; + + return saveFile(fileName); +} + +void TextEdit::loadFile(const QString &fileName) +{ + QFile file(fileName); + if (!file.open(QFile::ReadOnly | QFile::Text)) { + QMessageBox::warning(this, tr("Application"), + tr("Cannot read file %1:\n%2.") + .arg(fileName) + .arg(file.errorString())); + return; + } + QTextStream in(&file); + QApplication::setOverrideCursor(Qt::WaitCursor); + this->setPlainText(in.readAll()); + QApplication::restoreOverrideCursor(); + + setCurrentFile(fileName); + // statusBar()->showMessage(tr("File loaded"), 2000); +} + +void TextEdit::setCurrentFile(const QString &fileName) +{ + curFile = fileName; + this->document()->setModified(false); + setWindowModified(false); + + QString shownName; + if (curFile.isEmpty()) + shownName = "untitled.txt"; + else + shownName = strippedName(curFile); + + //setWindowTitle(tr("%1[*] - %2").arg(shownName).arg(qApp->applicationName())); +} + +QString TextEdit::strippedName(const QString &fullFileName) +{ + return QFileInfo(fullFileName).fileName(); +} + +bool TextEdit::maybeSave() +{ + if (this->document()->isModified()) { + QMessageBox::StandardButton ret; + ret = QMessageBox::warning(this, tr("Application"), + tr("The document has been modified.\nDo you want to save your changes?"), + QMessageBox::Save | QMessageBox::Discard | QMessageBox::Cancel); + if (ret == QMessageBox::Save) + return save(); + else if (ret == QMessageBox::Cancel) + return false; + } + return true; +} + +bool TextEdit::saveFile(const QString &fileName) +{ + QFile file(fileName); + if (!file.open(QFile::WriteOnly | QFile::Text)) { + QMessageBox::warning(this, tr("File"), + tr("Cannot write file %1:\n%2.") + .arg(fileName) + .arg(file.errorString())); + return false; + } + QTextStream out(&file); + QApplication::setOverrideCursor(Qt::WaitCursor); + out << this->toPlainText(); + QApplication::restoreOverrideCursor(); + //statusBar()->showMessage(tr("Saved '%1'").arg(fileName), 2000); + return true; +} +void TextEdit::print() +{ +#ifndef QT_NO_PRINTER + QTextDocument *document = this->document(); + QPrinter printer; + + QPrintDialog *dlg = new QPrintDialog(&printer, this); + if (dlg->exec() != QDialog::Accepted) + return; + + document->print(&printer); + + //statusBar()->showMessage(tr("Ready"), 2000); +#endif +} @@ -3,21 +3,37 @@ #include <QPlainTextEdit> -class QtGui; -class QApplication; +#include <QtGui> +#include <QFileDialog> +#include <QMessageBox> +#include <QFileInfo> +#include <QApplication> +#include <QFile> + class QWidget; +class QString; class TextEdit : public QPlainTextEdit { Q_OBJECT public: TextEdit(QWidget *parent=0); - -private: - bool isKey(QString key); + void setCurrentFile(const QString &fileName); + void loadFile(const QString &fileName); + bool maybeSave(); public slots: void quote(); + bool save(); + bool saveAs(); + void open(); + void print(); + +private: + bool isKey(QString key); + bool saveFile(const QString &fileName); + QString strippedName(const QString &fullFileName); + QString curFile; protected: void dragEnterEvent(QDragEnterEvent *event); |