From 9ce020813588612f52d4bfbc654979419c3929a7 Mon Sep 17 00:00:00 2001 From: Toni Gundogdu Date: Mon, 21 Dec 2009 21:12:57 +0200 Subject: [PATCH] add import/export list items under Edit menu. --- CHANGES | 6 ++ abby.pro | 5 +- rc/exportdlg.ui | 180 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ rc/mainwnd.ui | 57 ++++++++++++++++- src/exportdlg.cpp | 40 ++++++++++++ src/exportdlg.h | 35 +++++++++++ src/mainwnd.cpp | 45 ++++++++++++++ src/mainwnd.h | 2 + src/util.cpp | 67 ++++++++++++++++++++ src/util.h | 4 ++ 10 files changed, 439 insertions(+), 2 deletions(-) create mode 100644 rc/exportdlg.ui create mode 100644 src/exportdlg.cpp create mode 100644 src/exportdlg.h diff --git a/CHANGES b/CHANGES index 3fc62dc..82a6e1a 100644 --- a/CHANGES +++ b/CHANGES @@ -1,3 +1,9 @@ +Version 0.4.8 + + User-visible changes: + * Add import/export list items under Edit menu + + Version 0.4.7 (December 18, 2009) diff --git a/abby.pro b/abby.pro index f4d8ca1..b65ccd9 100644 --- a/abby.pro +++ b/abby.pro @@ -1,5 +1,5 @@ ###################################################################### -# Automatically generated by qmake (2.01a) Thu Dec 10 23:11:48 2009 +# Automatically generated by qmake (2.01a) Mon Dec 21 19:49:40 2009 ###################################################################### QT+=network xml @@ -10,6 +10,7 @@ INCLUDEPATH += . src # Input HEADERS += src/aboutdlg.h \ + src/exportdlg.h \ src/feededitdlg.h \ src/feedmgrdlg.h \ src/formatdlg.h \ @@ -21,6 +22,7 @@ HEADERS += src/aboutdlg.h \ src/scandlg.h \ src/util.h FORMS += rc/aboutdlg.ui \ + rc/exportdlg.ui \ rc/feededitdlg.ui \ rc/feedmgrdlg.ui \ rc/formatdlg.ui \ @@ -29,6 +31,7 @@ FORMS += rc/aboutdlg.ui \ rc/rssdlg.ui \ rc/scandlg.ui SOURCES += src/aboutdlg.cpp \ + src/exportdlg.cpp \ src/feededitdlg.cpp \ src/feedmgrdlg.cpp \ src/formatdlg.cpp \ diff --git a/rc/exportdlg.ui b/rc/exportdlg.ui new file mode 100644 index 0000000..2404c19 --- /dev/null +++ b/rc/exportdlg.ui @@ -0,0 +1,180 @@ + + + ExportDialog + + + + 0 + 0 + 400 + 164 + + + + Export + + + + + + true + + + + + + + + &File: + + + fileEdit + + + + + + + + + + Browse + + + + + + + :/folder-saved-search.png:/folder-saved-search.png + + + + 16 + 16 + + + + + + + + + + Options + + + + + + + + &Append to file + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + + + Qt::Vertical + + + + 20 + 40 + + + + + + + + + + + Qt::Horizontal + + + QDialogButtonBox::Cancel|QDialogButtonBox::Ok + + + + + + + fileEdit + browseButton + appendBox + buttonBox + + + + + + + buttonBox + accepted() + ExportDialog + accept() + + + 227 + 137 + + + 157 + 163 + + + + + buttonBox + rejected() + ExportDialog + reject() + + + 295 + 143 + + + 286 + 163 + + + + + browseButton + clicked() + ExportDialog + onBrowse() + + + 374 + 23 + + + 199 + 81 + + + + + + onBrowse() + + diff --git a/rc/mainwnd.ui b/rc/mainwnd.ui index dd49d00..284aecb 100644 --- a/rc/mainwnd.ui +++ b/rc/mainwnd.ui @@ -8,7 +8,7 @@ 0 0 545 - 389 + 391 @@ -741,6 +741,9 @@ the download reches the specified percent complete + + + @@ -918,6 +921,24 @@ the download reches the specified percent complete &Supported hosts... + + + + :/document-open.png:/document-open.png + + + Import... + + + + + + :/document-save.png:/document-save.png + + + Export... + + addButton @@ -1265,6 +1286,38 @@ the download reches the specified percent complete + + action_Import + activated() + MainWindow + onImport() + + + -1 + -1 + + + 272 + 195 + + + + + action_Export + activated() + MainWindow + onExport() + + + -1 + -1 + + + 272 + 195 + + + onStart() @@ -1284,5 +1337,7 @@ the download reches the specified percent complete onRemove() onFormats() onClear() + onImport() + onExport() diff --git a/src/exportdlg.cpp b/src/exportdlg.cpp new file mode 100644 index 0000000..98b9e2e --- /dev/null +++ b/src/exportdlg.cpp @@ -0,0 +1,40 @@ +/* +* Copyright (C) 2009 Toni Gundogdu. +* +* 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 "exportdlg.h" + +ExportDialog::ExportDialog(QWidget *parent) + : QDialog(parent) +{ + setupUi(this); +} + +void +ExportDialog::onBrowse() { + const QString fname = + QFileDialog::getSaveFileName(this, tr("Choose file")); + + if (fname.isEmpty()) + return; + + fileEdit->setText(fname); +} + + diff --git a/src/exportdlg.h b/src/exportdlg.h new file mode 100644 index 0000000..648414a --- /dev/null +++ b/src/exportdlg.h @@ -0,0 +1,35 @@ +/* +* Copyright (C) 2009 Toni Gundogdu. +* +* 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 . +*/ + +#ifndef exportdlg_h +#define exportdlg_h + +#include "ui_exportdlg.h" + +class QDialog; + +class ExportDialog : public QDialog, public Ui::ExportDialog { + Q_OBJECT +public: + ExportDialog(QWidget *parent); +private slots: + void onBrowse(); +}; + +#endif + + diff --git a/src/mainwnd.cpp b/src/mainwnd.cpp index 01ecd45..1fa9105 100644 --- a/src/mainwnd.cpp +++ b/src/mainwnd.cpp @@ -33,6 +33,7 @@ #include "scandlg.h" #include "formatdlg.h" #include "aboutdlg.h" +#include "exportdlg.h" #include "util.h" #define critCcliveProcessFailed(parent, msg) \ @@ -895,4 +896,48 @@ MainWindow::createTrayIcon() { ); } +void +MainWindow::onImport() { + QString fname = + QFileDialog::getOpenFileName(this, tr("Choose file")); + + if (!fname.isEmpty()) { + + QStringList lst; + if (!Util::importItems(this, lst, fname)) + return; + + for (QStringList::const_iterator iter = lst.begin(); + iter != lst.end(); + ++iter) + { + addPageLink(*iter); + } + } +} + +void +MainWindow::onExport() { + + if (!linksList->count()) + return; + + ExportDialog dlg(this); + if (dlg.exec() == QDialog::Rejected) + return; + + const QString path = dlg.fileEdit->text(); + + if (path.isEmpty()) { + QMessageBox::critical( + this, + QCoreApplication::applicationName(), + tr("Specify file name for the saved data") + ); + return; + } + + Util::exportItems(this, linksList, path, dlg.appendBox->isChecked()); +} + diff --git a/src/mainwnd.h b/src/mainwnd.h index 2d55345..d5d6d0b 100644 --- a/src/mainwnd.h +++ b/src/mainwnd.h @@ -54,6 +54,8 @@ private slots: void onProcFinished(int exitCode, QProcess::ExitStatus exitStatus); void onItemDoubleClicked(QListWidgetItem *item); void iconActivated(QSystemTrayIcon::ActivationReason); + void onImport(); + void onExport(); private: QStringMap hosts; PreferencesDialog *prefs; diff --git a/src/util.cpp b/src/util.cpp index 8f1a6b5..0d8229e 100644 --- a/src/util.cpp +++ b/src/util.cpp @@ -29,6 +29,8 @@ #include #include #include +#include +#include //#include #include "util.h" @@ -314,6 +316,71 @@ Util::paste(const QListWidget *w) { Util::addItem(w, lst[i]); } +static void +msgbox_crit( + const QWidget *parent, + const QString msg) +{ + QMessageBox::critical( + const_cast(parent), + QCoreApplication::applicationName(), + msg); +} + +bool +Util::importItems( + const QWidget *parent, + QStringList& lst, + const QString& path) +{ + QFile file(path); + + if (!file.open(QFile::ReadOnly | QIODevice::Text)) { + msgbox_crit(parent, + QString( QObject::tr("File open error %1") ).arg( file.error() )); + return false; + } + + QTextStream f(&file); + + while (!f.atEnd()) + lst.append(f.readLine().simplified()); + + return !lst.empty(); +} + +bool +Util::exportItems( + const QWidget *parent, + const QListWidget *w, + const QString& path, + const bool& append) +{ + QFile file(path); + + QFlags flags = + (QFile::WriteOnly | QIODevice::Text); + + flags |= + append + ? QIODevice::Append + : QIODevice::Truncate; + + if (!file.open(flags)) { + msgbox_crit(parent, + QString( QObject::tr("File open error %1") ).arg( file.error() )); + return false; + } + + QTextStream out(&file); + + const int size = w->count(); + for (int i=0; iitem(i)->text() << "\n"; + + return true; +} + NoCcliveException::NoCcliveException(const QString& errmsg) : errmsg(errmsg) { diff --git a/src/util.h b/src/util.h index ad496d5..a8021fd 100644 --- a/src/util.h +++ b/src/util.h @@ -54,6 +54,10 @@ public: static void removeSelectedItems(const QWidget *parent, const QListWidget *w); static void clearItems(const QWidget *parent, const QListWidget *w); static void paste(const QListWidget *w); + static bool importItems(const QWidget *parent, + QStringList& lst, const QString& path); + static bool exportItems(const QWidget *parent, + const QListWidget *w, const QString& path, const bool& append); }; class NoCcliveException { -- 2.11.4.GIT