aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--TODO1
-rw-r--r--gpgwin.cpp25
-rw-r--r--keylist.h3
-rwxr-xr-xquitdialog.cpp1
-rwxr-xr-xquitdialog.h18
-rw-r--r--textedit.cpp189
-rw-r--r--textedit.h69
7 files changed, 167 insertions, 139 deletions
diff --git a/TODO b/TODO
index 92dea64..2b475ff 100644
--- a/TODO
+++ b/TODO
@@ -36,6 +36,7 @@ attachments:
- add quote button
- fix overwrite file bug in file encryption [DONE]
- add drag'n'drop features for keys [DONE]
+- add posibility to change password of key
Release 0.3
- PGP-MIME, find and show inline encrypted files
diff --git a/gpgwin.cpp b/gpgwin.cpp
index 17062cc..a7b04b4 100644
--- a/gpgwin.cpp
+++ b/gpgwin.cpp
@@ -32,7 +32,6 @@ GpgWin::GpgWin()
QString appPath = qApp->applicationDirPath();
iconPath = appPath + "/icons/";
-
setCorner(Qt::BottomLeftCorner, Qt::LeftDockWidgetArea);
setCorner(Qt::BottomRightCorner, Qt::RightDockWidgetArea);
@@ -61,14 +60,13 @@ GpgWin::GpgWin()
// open filename if provided as first command line parameter
QStringList args = qApp->arguments();
- qDebug() << args.size();
if (args.size() > 1) {
-
if (!args[1].startsWith("-")) {
if (QFile::exists(args[1]))
edit->loadFile(args[1]);
}
}
+
edit->curTextPage()->setFocus();
}
@@ -451,7 +449,7 @@ void GpgWin::about()
"<b>Developer:</b><br>"
"Bene, Heimer, Juergen, Nils, Ubbo<br><br>"
"<b>Translation:</b><br>"
- "Alessandro (pt_br), Alex (fr), Kirill (ru), Viriato (es), Serse (it) <br><br>"
+ "Alessandro (pt_br), Kirill (ru), Viriato (es), Serse (it) <br><br>"
"If you have any questions and/or<br>"
"suggestions, contact us at<br>"
"gpg4usb at cpunk.de</a><br><br>"
@@ -491,28 +489,21 @@ void GpgWin::decrypt()
if(Mime::isMime(decrypted)) {
Header header = Mime::getHeader(decrypted);
-
// is it multipart, is multipart-parsing enabled
if(header.getValue("Content-Type") == "multipart/mixed"
&& settings.value("mime/parseMime").toBool()) {
-
parseMime(decrypted);
-
} else if(header.getValue("Content-Type") == "text/plain"
&& settings.value("mime/parseQP").toBool()){
-
- if (header.getValue("Content-Transfer-Encoding") == "quoted-printable") {
- QByteArray *decoded = new QByteArray();
- Mime::quotedPrintableDecode(*decrypted, *decoded);
- //TODO: remove header
- decrypted = decoded;
-
- }
+ if (header.getValue("Content-Transfer-Encoding") == "quoted-printable") {
+ QByteArray *decoded = new QByteArray();
+ Mime::quotedPrintableDecode(*decrypted, *decoded);
+ //TODO: remove header
+ decrypted = decoded;
+ }
}
}
-
edit->curTextPage()->setPlainText(QString::fromUtf8(*decrypted));
- //edit->setPlainText(*decrypted);
}
}
diff --git a/keylist.h b/keylist.h
index 94050f9..1806c79 100644
--- a/keylist.h
+++ b/keylist.h
@@ -26,11 +26,8 @@
class QWidget;
class QVBoxLayout;
-class QTableWidgetItem;
class QLabel;
-class QMessageBox;
class QTableWidget;
-class QPushButton;
class QMenu;
class KeyList : public QWidget
diff --git a/quitdialog.cpp b/quitdialog.cpp
index 6e64065..baf352a 100755
--- a/quitdialog.cpp
+++ b/quitdialog.cpp
@@ -23,7 +23,6 @@
#include <QtGui>
#include <QTableWidget>
#include "quitdialog.h"
-class QMessageBox;
QuitDialog::QuitDialog(QWidget *parent, QHash<int, QString> unsavedDocs, QString iconPath)
: QDialog(parent)
diff --git a/quitdialog.h b/quitdialog.h
index 0dd4bf5..58f1e45 100755
--- a/quitdialog.h
+++ b/quitdialog.h
@@ -22,22 +22,9 @@
#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 QTableWidget;
+
class QuitDialog : public QDialog
{
Q_OBJECT
@@ -48,7 +35,6 @@ public:
QList <int> getTabIdsToSave();
private slots:
-// void accept();
void myDiscard();
private:
diff --git a/textedit.cpp b/textedit.cpp
index 3ef84ba..8595c4b 100644
--- a/textedit.cpp
+++ b/textedit.cpp
@@ -20,7 +20,6 @@
*/
#include "QDebug"
-#include "QUrl"
#include "textedit.h"
#include "quitdialog.h"
class QFileDialog;
@@ -29,7 +28,7 @@ class QMessageBox;
TextEdit::TextEdit(QString iconPath)
{
mIconPath = iconPath;
- countPage = 0;
+ countPage = 0;
tabWidget = new QTabWidget(this);
tabWidget->setMovable(true);
tabWidget->setTabsClosable(true);
@@ -48,8 +47,8 @@ TextEdit::TextEdit(QString iconPath)
void TextEdit::newTab()
{
- QString header = "new " +
- QString::number(++countPage);
+ QString header = tr("untitled") +
+ QString::number(++countPage)+".txt";
EditorPage *page = new EditorPage();
tabWidget->addTab(page, header);
@@ -59,18 +58,15 @@ void TextEdit::newTab()
// setCursorPosition();
}
-
void TextEdit::open()
{
QStringList fileNames = QFileDialog::getOpenFileNames(this, tr("Open file"),
QDir::currentPath());
foreach (QString fileName,fileNames){
- if (!fileName.isEmpty())
- {
+ if (!fileName.isEmpty()) {
QFile file(fileName);
- if (file.open(QIODevice::ReadOnly | QIODevice::Text))
- {
+ if (file.open(QIODevice::ReadOnly | QIODevice::Text)) {
EditorPage *page = new EditorPage(fileName);
QTextStream in(&file);
@@ -87,9 +83,7 @@ void TextEdit::open()
connect(page->getTextPage(), SIGNAL(modificationChanged(bool)), this, SLOT(showModified()));
// setCursorPosition();
//enableAction(true)
- }
- else
- {
+ } else {
QMessageBox::warning(this, tr("Application"),
tr("Cannot read file %1:\n%2.")
.arg(fileName)
@@ -99,35 +93,28 @@ void TextEdit::open()
}
}
-
void TextEdit::save()
{
QString fileName = curPage()->getFilePath();
- qDebug() <<fileName;
- if (fileName.isEmpty())
- {
+ if (fileName.isEmpty()) {
+ //QString docname = tabWidget->tabText(tabWidget->currentIndex());
+ //docname.remove(0,2);
saveAs();
- }
- else
- {
+ } else {
saveFile(fileName);
}
}
-
bool TextEdit::saveFile(const QString &fileName)
{
- if (fileName.isEmpty())
- {
+ if (fileName.isEmpty()) {
return false;
}
-
QFile file(fileName);
- if (file.open(QIODevice::WriteOnly | QIODevice::Text))
- {
+ if (file.open(QIODevice::WriteOnly | QIODevice::Text)) {
QTextStream outputStream(&file);
EditorPage *page = curPage();
@@ -138,18 +125,15 @@ bool TextEdit::saveFile(const QString &fileName)
int curIndex = tabWidget->currentIndex();
tabWidget->setTabText(curIndex, strippedName(fileName));
- page->setFilePath(fileName);
+ page->setFilePath(fileName);
// statusBar()->showMessage(tr("File saved"), 2000);
return true;
- }
- else
- {
+ } else {
QMessageBox::warning(this, tr("File"),
tr("Cannot write file %1:\n%2.")
.arg(fileName)
.arg(file.errorString()));
-
return false;
}
}
@@ -157,9 +141,8 @@ bool TextEdit::saveFile(const QString &fileName)
bool TextEdit::saveAs()
{
- QString fileName = QFileDialog::getSaveFileName(this, tr("Save file"),
+ QString fileName = QFileDialog::getSaveFileName(this, tr("Save file "),
QDir::currentPath());
-
return saveFile(fileName);
}
@@ -177,15 +160,18 @@ void TextEdit::closeTab()
void TextEdit::removeTab(int index)
{
+ // Do nothing, if no tab is opened
if (tabWidget->count() == 0) {
return;
}
+ // get the index of the actual current tab
int lastIndex = tabWidget->currentIndex();
+
+ // set the focus to argument index
tabWidget->setCurrentIndex(index);
- if (maybeSaveCurrentTab()) {
- //curPage()->close();
+ if (maybeSaveCurrentTab(true)) {
tabWidget->removeTab(index);
if(index >= lastIndex) {
@@ -200,39 +186,6 @@ void TextEdit::removeTab(int index)
}
}
-void TextEdit::cut()
-{
- curTextPage()->cut();
-}
-
-
-void TextEdit::copy()
-{
- curTextPage()->copy();
-}
-
-
-void TextEdit::paste()
-{
- curTextPage()->paste();
-}
-
-
-void TextEdit::undo()
-{
- curTextPage()->undo();
-}
-
-
-void TextEdit::redo()
-{
- curTextPage()->redo();
-}
-
-void TextEdit::selectAll()
-{
- curTextPage()->selectAll();
-}
/**
* Check if current may need to be saved.
@@ -240,20 +193,27 @@ void TextEdit::selectAll()
*
* If it returns false, the close event should be aborted.
*/
-bool TextEdit::maybeSaveCurrentTab() {
+bool TextEdit::maybeSaveCurrentTab(bool askToSave) {
EditorPage *page = curPage();
QTextDocument *document = page->getTextPage()->document();
- if (document->isModified())
- {
- QString filePath = page->getFilePath();
+ if (document->isModified()) {
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);
- if (result == QMessageBox::Save) {
+ // write title of tab to docname and remove the leading *
+ QString docname = tabWidget->tabText(tabWidget->currentIndex());
+ docname.remove(0,2);
+
+ QString filePath = page->getFilePath();
+ if (askToSave) {
+ result = QMessageBox::warning(this, tr("Unsaved document"),
+ tr("The document has been modified:")+"\n\n"+docname+"\n\n\n"+tr("Do you want to save your changes?"),
+ QMessageBox::Save | QMessageBox::Discard | QMessageBox::Cancel);
+ }
+ if ((result == QMessageBox::Save) || (!askToSave)) {
if (filePath == "") {
+ //QString docname = tabWidget->tabText(tabWidget->currentIndex());
+ //docname.remove(0,2);
return saveAs();
} else {
return saveFile(filePath);
@@ -292,7 +252,7 @@ bool TextEdit::maybeSaveAnyTab()
if(unsavedDocs.size() == 1) {
int modifiedTab = unsavedDocs.keys().at(0);
tabWidget->setCurrentIndex(modifiedTab);
- return maybeSaveCurrentTab();
+ return maybeSaveCurrentTab(true);
}
/*
@@ -317,16 +277,16 @@ bool TextEdit::maybeSaveAnyTab()
bool allsaved=true;
QList <int> tabIdsToSave = dialog->getTabIdsToSave();
- foreach (int tabId, tabIdsToSave){
+ foreach (int tabId, tabIdsToSave) {
tabWidget->setCurrentIndex(tabId);
- if (! maybeSaveCurrentTab()) {
+ if (! maybeSaveCurrentTab(false)) {
allsaved=false;
}
}
if (allsaved) {
- return true;
+ return true;
} else {
- return false;
+ return false;
}
}
}
@@ -359,8 +319,9 @@ void TextEdit::quote()
while (!cursor.isNull() && !cursor.atEnd()) {
cursor.movePosition(QTextCursor::EndOfLine);
cursor.movePosition(QTextCursor::NextCharacter);
- if(!cursor.atEnd())
+ if(!cursor.atEnd()) {
cursor.insertText("> ");
+ }
}
cursor.endEditBlock();
}
@@ -397,9 +358,9 @@ void TextEdit::print()
QPrinter printer;
QPrintDialog *dlg = new QPrintDialog(&printer, this);
- if (dlg->exec() != QDialog::Accepted)
+ if (dlg->exec() != QDialog::Accepted) {
return;
-
+ }
document->print(&printer);
//statusBar()->showMessage(tr("Ready"), 2000);
@@ -411,36 +372,32 @@ void TextEdit::print()
void TextEdit::showModified() {
int index=tabWidget->currentIndex();
QString title= tabWidget->tabText(index);
- if(curTextPage()->document()->isModified())
+ // if doc is modified now, add leading * to title,
+ // otherwise remove the leading * from the title
+ if(curTextPage()->document()->isModified()) {
tabWidget->setTabText(index, title.prepend("* "));
- else
+ } else {
tabWidget->setTabText(index, title.remove(0,2));
+ }
}
void TextEdit::switchTabUp() {
- if (tabWidget->count() > 1)
- {
- if (tabWidget->count() == tabWidget->currentIndex()+1){
- tabWidget->setCurrentIndex(0);
- } else {
- tabWidget->setCurrentIndex(tabWidget->currentIndex()+1);
- }
+ if (tabWidget->count() > 1) {
+ int newindex=(tabWidget->currentIndex()+1)%(tabWidget->count());
+ tabWidget->setCurrentIndex(newindex);
}
}
void TextEdit::switchTabDown() {
- if (tabWidget->count() > 1)
- {
- if (tabWidget->currentIndex()==1) {
- tabWidget->setCurrentIndex(tabWidget->count()-1);
- } else {
- tabWidget->setCurrentIndex(tabWidget->currentIndex()-1);
- }
+ if (tabWidget->count() > 1) {
+ int newindex=(tabWidget->currentIndex()-1+tabWidget->count())%tabWidget->count();
+ tabWidget->setCurrentIndex(newindex);
}
- this->removeTab(0);
}
-
+/*
+ * return a hash of tabindexes and title of unsaved tabs
+ */
QHash<int, QString> TextEdit::unsavedDocuments() {
QHash<int, QString> unsavedDocs; // this list could be used to implement gedit like "unsaved changed"-dialog
@@ -456,6 +413,36 @@ QHash<int, QString> TextEdit::unsavedDocuments() {
return unsavedDocs;
}
+void TextEdit::cut()
+{
+ curTextPage()->cut();
+}
+
+void TextEdit::copy()
+{
+ curTextPage()->copy();
+}
+
+void TextEdit::paste()
+{
+ curTextPage()->paste();
+}
+
+void TextEdit::undo()
+{
+ curTextPage()->undo();
+}
+
+void TextEdit::redo()
+{
+ curTextPage()->redo();
+}
+
+void TextEdit::selectAll()
+{
+ curTextPage()->selectAll();
+}
+
/*void TextEdit::dragEnterEvent(QDragEnterEvent *event)
{
if (event->mimeData()->hasFormat("text/plain"))
diff --git a/textedit.h b/textedit.h
index 091ce9d..1e05a35 100644
--- a/textedit.h
+++ b/textedit.h
@@ -43,17 +43,68 @@ public:
TextEdit(QString iconPath);
void loadFile(const QString &fileName);
bool maybeSaveAnyTab();
- bool maybeSaveCurrentTab();
QPlainTextEdit* curTextPage();
QHash<int, QString> unsavedDocuments();
public slots:
void quote();
+
+ /****************************************************************************************
+ * Name: save
+ * Description: Saves the content of the current tab, if it has a filepath
+ * otherwise it calls saveAs for the current tab
+ * Parameters: none
+ * Return Values: none
+ * Change on members:
+ */
void save();
+
+ /****************************************************************************************
+ * Name: SaveAs
+ * Description: Opens a savefiledialog and calls saveFile with the choosen filename
+ * Parameters: none
+ * Return Values: just returns the return value of the saveFile method
+ * Change on members: none
+ */
bool saveAs();
+
+ /****************************************************************************************
+ * Name: open
+ * Description: shows an OpenFileDoalog and opens the file in a new tab
+ * shows an error dialog, if the open fails
+ * sets the focus to the tab of the opened file
+ * Parameters: none
+ * Return Values: none
+ * Change on members: none
+ */
void open();
+
+ /****************************************************************************************
+ * Name: print
+ * Description: opens print dialog for the current tab
+ * Parameters: none
+ * Return Values: none
+ * Change on members: none
+ */
void print();
+
+ /****************************************************************************************
+ * Name: newTab()
+ * Description: Adds a new tab with the title "untitled"+countpage+".txt"
+ * Sets the focus to the new tab
+ * Parameters: none
+ * Return Values: none
+ * Change on members: increases countPage per 1
+ */
void newTab();
+
+ /****************************************************************************************
+ * Name:
+ * Description:
+ * Parameters:
+ * Return Values:
+ * Change on members:
+ */
void showModified();
void closeTab();
void switchTabUp();
@@ -67,8 +118,16 @@ private:
QString mIconPath;
int countPage;
QTabWidget *tabWidget;
+ bool maybeSaveCurrentTab(bool askToSave);
private slots:
+ /****************************************************************************************
+ * Name: removeTab
+ * Description: Removes the tab on index
+ * Parameters: int index, shows the index of the tab to remove
+ * Return Values: none
+ * Change on members: none
+ */
void removeTab(int index);
void cut();
void copy();
@@ -80,6 +139,14 @@ private slots:
protected:
// void dragEnterEvent(QDragEnterEvent *event);
// void dropEvent(QDropEvent* event);
+ /****************************************************************************************
+ * Name: saveFile
+ * Description: Saves the content of currentTab to the file filename
+ * Parameters: QString filename contains the full path of the file to save
+ * Return Values: true, if the file was saved succesfully
+ * false, if parameter filename is empty or the saving failed
+ * Change on members: sets isModified of the current tab to false
+ */
bool saveFile(const QString &fileName);
};
#endif // TEXTEDIT