X-Git-Url: http://vcs.maemo.org/git/?a=blobdiff_plain;f=src%2Fshowfulllistdialog.cpp;fp=src%2Fshowfulllistdialog.cpp;h=ee80f7ffc7e6c3e4eb03f4de73c21b2dab9ceb87;hb=820183c689df1ac8836f05634f0055480a3acb84;hp=0000000000000000000000000000000000000000;hpb=f2bf362b48af28406e3a4cf36deed71e53e0cc03;p=push-it diff --git a/src/showfulllistdialog.cpp b/src/showfulllistdialog.cpp new file mode 100644 index 0000000..ee80f7f --- /dev/null +++ b/src/showfulllistdialog.cpp @@ -0,0 +1,98 @@ +/* + Copyright (C) <2010> + + 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 3 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, see . +*/ +#include +#include +#include +#include +#include + +#include +#include + +#include "showfulllistdialog.hpp" + +ShowFullListDialog::ShowFullListDialog(QWidget *parent, QString text) : + QDialog(parent) +{ + QPushButton *doneButton = new QPushButton(tr("&Done")); + QPushButton *saveButton = new QPushButton(tr("&Save")); + QPushButton *saveEditedButton = new QPushButton(tr("S&ave edited version")); + textEdit = new QTextBrowser; + textEdit->setReadOnly(false); + textEdit->setText(text); + initialString = text; + + QVBoxLayout *layout = new QVBoxLayout; + layout->addWidget(doneButton); + layout->addWidget(saveButton); + layout->addWidget(saveEditedButton); + layout->addStretch(); + + QHBoxLayout *mainLayout = new QHBoxLayout; + mainLayout->addLayout(layout); + mainLayout->addWidget(textEdit); + + connect(doneButton, SIGNAL(clicked()), this, SLOT(deleteLater())); + connect(saveButton, SIGNAL(clicked()), this, SLOT(save())); + connect(saveEditedButton, SIGNAL(clicked()), this, SLOT(saveEdited())); + + setLayout(mainLayout); + setWindowTitle(tr("History")); + setBaseSize(700,400); + setMinimumWidth(600); + setMinimumHeight(400); + hide(); +} + +ShowFullListDialog::~ShowFullListDialog() +{ +} + +int ShowFullListDialog::saveToFile(QString string) +{ + QString fileName = QFileDialog::getSaveFileName(0, + tr("Save to"), "", + tr("Push-It textfile (*.pushit);;All Files (*.*)")); + if (fileName.isEmpty()) + { + return EXIT_FAILURE; + } + else + { + std::ofstream myfile; + myfile.open(fileName.toStdString().c_str()); + if (!myfile.is_open()) + { + QMessageBox::information(0, tr("Unable to open file"), + tr("Unable to open file")); + return EXIT_FAILURE; + } + myfile << string.toStdString(); + myfile.close(); + } + return EXIT_SUCCESS; +} + +void ShowFullListDialog::save() +{ + saveToFile(initialString); +} + +void ShowFullListDialog::saveEdited() +{ + saveToFile(textEdit->toPlainText()); +}