[repo.or.cz] nomnom.git branch next updated: v0.2.0-15-gc98e0b6
Brought to you by:
legatvs
|
From: <nom...@li...> - 2011-10-27 19:55:35
|
This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project nomnom.git.
The branch, next has been updated
via c98e0b65eef6a2115eae15fa13fef9a89374ba53 (commit)
via fb3dd47a41c948cacfc5d697fa8ee267989ea7af (commit)
from 2b9280145afba0e226448b5711ad499d2844982d (commit)
Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.
- Log -----------------------------------------------------------------
http://repo.or.cz/w/nomnom.git/commit/c98e0b65eef6a2115eae15fa13fef9a89374ba53
commit c98e0b65eef6a2115eae15fa13fef9a89374ba53
Author: Toni Gundogdu <le...@gm...>
Date: Thu Oct 27 18:51:32 2011 +0300
Use NUtil 'info' and 'ask' instead
diff --git a/src/log/nlogdialog.cpp b/src/log/nlogdialog.cpp
index 9fca6d4..695d9ad 100644
--- a/src/log/nlogdialog.cpp
+++ b/src/log/nlogdialog.cpp
@@ -24,6 +24,8 @@
#include <QToolBox>
#include <NLogDialog>
+#include <NSettings>
+#include <NUtil>
namespace nn
{
@@ -84,7 +86,7 @@ void NLogDialog::done(int n)
if (_selected.isEmpty())
{
_toolbox->setCurrentIndex(0);
- m_info(tr("Please select an item from the list"));
+ info(this, tr("Please select an item from the list"));
return;
}
}
@@ -102,11 +104,6 @@ QString NLogDialog::selected() const
return _selected;
}
-void NLogDialog::m_info(const QString& msg)
-{
- QMessageBox::information(this, QCoreApplication::applicationName(), msg);
-}
-
// NLogWidget
NLogWidget::NLogWidget(QWidget *parent/*=NULL*/)
diff --git a/src/log/nlogdialog.h b/src/log/nlogdialog.h
index 5635794..33313c7 100644
--- a/src/log/nlogdialog.h
+++ b/src/log/nlogdialog.h
@@ -36,7 +36,6 @@ public:
protected:
void done(int);
private:
- void m_info(const QString& msg);
void foreachWidget();
private slots:
void selected(QString);
@@ -75,8 +74,6 @@ protected:
virtual void read();
#endif
private:
- int confirmClear();
-private:
QTreeWidget *_treew;
};
diff --git a/src/log/nlogdialog_recent.cpp b/src/log/nlogdialog_recent.cpp
index 775ff94..6b0cb5e 100644
--- a/src/log/nlogdialog_recent.cpp
+++ b/src/log/nlogdialog_recent.cpp
@@ -28,6 +28,8 @@
#include <NRecentMutator>
#include <NRecentEntry>
#include <NLogDialog>
+#include <NSettings>
+#include <NUtil>
extern nn::NRecentMutator recent;
@@ -82,22 +84,16 @@ void NLogRecent::selected()
emit selected(i->text(0));
}
-int NLogRecent::confirmClear()
-{
- return QMessageBox::question(this,
- qApp->applicationName(),
- tr("All records will be lost permanently. "
- "Really clear?"),
- QMessageBox::Yes|QMessageBox::No);
-}
-
void NLogRecent::reset()
{
if (_treew->topLevelItemCount() == 0)
return;
- if (confirmClear() != QMessageBox::Yes)
- return;
+ if (ask(this, tr("All records will be lost permanently. Really clear?"))
+ != QMessageBox::Yes)
+ {
+ return;
+ }
_treew->clear();
recent.clear();
http://repo.or.cz/w/nomnom.git/commit/fb3dd47a41c948cacfc5d697fa8ee267989ea7af
commit fb3dd47a41c948cacfc5d697fa8ee267989ea7af
Author: Toni Gundogdu <le...@gm...>
Date: Thu Oct 27 18:39:01 2011 +0300
Use NLogDialog instead
* Replace old "recent URL" subsystem
* Remove "using namespace nn"
* Add prerequisite for QJson
* Cleanup misc. comments
diff --git a/src/Makefile.am b/src/Makefile.am
index cd97339..db43bc5 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -15,8 +15,10 @@ nodist_nomnom_SOURCES= moc_nsettingsdialog.cpp moc_ndetectdialog.cpp moc_ntripwireedit.cpp + moc_nrecententry.cpp moc_naboutdialog.cpp moc_nfeeddialog.cpp + moc_nlogdialog.cpp moc_nsystray.cpp moc_MainWindow.cpp moc_DownloadDiag.cpp @@ -37,6 +39,12 @@ moc_DownloadDiag.cpp:
moc_ProcProgDiag.cpp:
$(MOC) -o $@ $(top_srcdir)/src/ProcProgDiag.h
+moc_nrecententry.cpp:
+ $(MOC) -o $@ $(top_srcdir)/src/log/nrecententry.h
+
+moc_nlogdialog.cpp:
+ $(MOC) -o $@ $(top_srcdir)/src/log/nlogdialog.h
+
moc_nerrorwhiledialog.cpp:
$(MOC) -o $@ $(top_srcdir)/src/errorwhile/nerrorwhiledialog.h
@@ -65,6 +73,20 @@ qrc_nomnom.cpp:
$(RCC) -o $@ $(top_srcdir)/src/rc/nomnom.qrc
src=+ about/naboutdialog.cpp + detect/ndetectdialog.cpp + detect/ndetect.cpp + errorwhile/nerrorwhiledialog.cpp + feed/nfeeddialog_properties.cpp + feed/nfeedprogressdialog.cpp + feed/nfeeddialog_items.cpp + feed/nfeeddialog.cpp + feed/nfeed.cpp + lang/nlang.cpp + log/nlogdialog_recent.cpp + log/nrecentmutator.cpp + log/nrecententry.cpp + log/nlogdialog.cpp settings/nsettingsdialog_options_appearance.cpp settings/nsettingsdialog_options_behaviour.cpp settings/nsettingsdialog_options_systray.cpp @@ -75,27 +97,22 @@ src= settings/nsettingsmutator.cpp settings/nsettingsdialog.cpp settings/nsettings.cpp - errorwhile/nerrorwhiledialog.cpp - widgets/ntripwireedit.cpp - detect/ndetectdialog.cpp - detect/ndetect.cpp - about/naboutdialog.cpp - feed/nfeeddialog_properties.cpp - feed/nfeedprogressdialog.cpp - feed/nfeeddialog_items.cpp - feed/nfeeddialog.cpp - feed/nfeed.cpp - lang/nlang.cpp - util/nutil.cpp systray/nsystray.cpp + util/nutil.cpp + widgets/ntripwireedit.cpp
i/MainWindow.cpp ProcProgDiag.cpp DownloadDiag.cpp main.cpp - Recent.cpp Media.cpp
hdr=+ NAboutDialog + about/naboutdialog.h + NDetectDialog + NDetect + detect/ndetectdialog.h + detect/ndetect.h NErrorWhileDialog errorwhile/nerrorwhiledialog.h NFeedProgressDialog @@ -104,30 +121,29 @@ hdr= feed/nfeedprogressdialog.h feed/nfeeddialog.h feed/nfeed.h + NLang + lang/nlang.h + NRecentMutator + NRecentEntry + NLogDialog + log/nrecentmutator.h + log/nrecententry.h + log/nlogdialog.h + NTripwireEdit + widgets/ntripwireedit.h NSettingsMutator NSettingsDialog NSettings settings/nsettingsmutator.h settings/nsettingsdialog.h settings/nsettings.h - NDetectDialog - NDetect - detect/ndetectdialog.h - detect/ndetect.h - NTripwireEdit - widgets/ntripwireedit.h NSysTray systray/nsystray.h - NAboutDialog - about/naboutdialog.h - NLang - lang/nlang.h NUtil util/nutil.h i/MainWindow.h ProcProgDiag.h DownloadDiag.h - Recent.h Media.h
bin_PROGRAMS= nomnom
diff --git a/src/NLogDialog b/src/NLogDialog
new file mode 100644
index 0000000..44029cf
--- /dev/null
+++ b/src/NLogDialog
@@ -0,0 +1 @@
+#include "log/nlogdialog.h"
diff --git a/src/NRecentEntry b/src/NRecentEntry
new file mode 100644
index 0000000..ea8b4d9
--- /dev/null
+++ b/src/NRecentEntry
@@ -0,0 +1 @@
+#include "log/nrecententry.h"
diff --git a/src/NRecentMutator b/src/NRecentMutator
new file mode 100644
index 0000000..9db9d85
--- /dev/null
+++ b/src/NRecentMutator
@@ -0,0 +1 @@
+#include "log/nrecentmutator.h"
diff --git a/src/Recent.cpp b/src/Recent.cpp
deleted file mode 100644
index a4a775e..0000000
--- a/src/Recent.cpp
+++ /dev/null
@@ -1,72 +0,0 @@
-/*
- * NomNom
- * Copyright (C) 2010 Toni Gundogdu <le...@gm...>
- *
- * 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 <http://www.gnu.org/licenses/>.
- */
-
-#include "config.h"
-
-#include <QSettings>
-#include <QDebug>
-
-#include "Recent.h"
-
-#define QSETTINGS_GROUP "Recent"
-
-Recent::Recent () :maxItems (10) { }
-Recent::~Recent () { }
-
-void
-Recent::write () const
-{
- QSettings ().setValue(QString("%1/drops").arg(QSETTINGS_GROUP), drops);
-}
-
-void
-Recent::read ()
-{
- drops = QSettings ().value (QString ("%1/drops")
- .arg (QSETTINGS_GROUP))
- .toStringList ();
-}
-
-void
-Recent::append(const QString& s)
-{
- drops.prepend(s);
- drops.removeDuplicates();
-
- if (drops.size() > maxItems)
- drops.takeFirst();
-}
-
-Recent&
-Recent::operator<<(const QString& s)
-{
- append (s);
- return *this;
-}
-
-QStringList Recent::toStringList () const
-{
- return drops;
-}
-
-void Recent::clear ()
-{
- drops.clear ();
-}
-
-// vim: set ts=2 sw=2 tw=72 expandtab:
diff --git a/src/i/MainWindow.cpp b/src/i/MainWindow.cpp
index 50c3dc1..cee1717 100644
--- a/src/i/MainWindow.cpp
+++ b/src/i/MainWindow.cpp
@@ -33,14 +33,16 @@
#include <NErrorWhileDialog>
#include <NSettingsMutator>
#include <NSettingsDialog>
+#include <NRecentMutator>
+#include <NRecentEntry>
#include <NAboutDialog>
#include <NFeedDialog>
+#include <NLogDialog>
#include <NSettings>
#include <NSysTray>
#include <NLang>
#include <NUtil>
-#include "Recent.h"
#include "DownloadDiag.h"
#include "ProcProgDiag.h"
#include "MainWindow.h"
@@ -52,10 +54,8 @@
extern bool have_quvi_feature_query_formats;
extern nn::NSettingsMutator settings;
extern bool have_umph_feature_all;
+extern nn::NRecentMutator recent;
extern nn::NSysTray *systray;
-extern Recent recent;
-
-// Modes.
enum { StreamMedia=0, DownloadMedia };
@@ -75,6 +75,10 @@ MainWindow::MainWindow()
connect(_proc, SIGNAL(finished(QString)),
this, SLOT(onProcFinished(QString)));
+// Read recent URLs into memory.
+
+ recent.read();
+
// Custom program icon.
#ifdef _1
@@ -117,7 +121,7 @@ void MainWindow::createContextMenu()
#undef add_s
#undef creat_a
- // Add key shortcuts.
+// Add key shortcuts.
#define _wrap(s,k) do { _actions[s]->setShortcut(QKeySequence(k)); } while (0)
@@ -131,13 +135,11 @@ void MainWindow::createContextMenu()
_wrap(tr("Quit"), "Ctrl+Q");
#undef _wrap
- // Add the context menu.
+// Add the context menu.
textBrowser->setContextMenuPolicy(Qt::ActionsContextMenu);
}
-// Create tray icon.
-
void MainWindow::createTrayIcon()
{
systray = new nn::NSysTray(this, QString("<b>NomNom</b> %1").arg(VN));
@@ -181,7 +183,12 @@ void MainWindow::createTrayIcon()
show();
}
-// Handle (dropped) URL.
+#ifdef ENABLE_VERBOSE
+static void print_url(const nn::NRecentEntry& r)
+{
+ qDebug() << __PRETTY_FUNCTION__ << __LINE__ << r.url();
+}
+#endif
void MainWindow::handleURL(const QString& url)
{
@@ -223,7 +230,14 @@ void MainWindow::handleURL(const QString& url)
// Recent.
- recent << url;
+ nn::NRecentEntry e;
+ e.setURL(url);
+
+ recent << e;
+
+#ifdef ENABLE_VERBOSE
+ recent.for_each(print_url);
+#endif
// 0x1=invalid input, 0x3=no input
@@ -288,11 +302,19 @@ void MainWindow::handleURL(const QString& url)
if (_proc->canceled())
return;
-// Download media or pass media stream URL to a media player.
+// Check for quvi errors.
QString errmsg;
if (parseOK(errmsg))
{
+ // Update recent entry. Media URL is set already. Update title
+ // only.
+
+ e.setTitle(_media.get(Media::PageTitle).toString().simplified());
+ recent.update(e);
+
+ // Download media or pass media stream URL.
+
if (modeCBox->currentIndex() == StreamMedia)
streamMedia();
else
@@ -309,8 +331,6 @@ void MainWindow::handleURL(const QString& url)
}
}
-// Query formats to an URL.
-
bool MainWindow::queryFormats(QStringList& formats,
const QStringList& q_args,
const QString& url,
@@ -361,8 +381,6 @@ bool MainWindow::queryFormats(QStringList& formats,
return false;
}
-// Select a format.
-
bool MainWindow::selectFormat(QStringList& formats, QString& fmt)
{
// Prompt only if count exceeds 1 ("default)".
@@ -395,8 +413,6 @@ bool MainWindow::selectFormat(QStringList& formats, QString& fmt)
return ok && !fmt.isEmpty();
}
-// View media (stream).
-
void MainWindow::streamMedia()
{
const QString p = settings.eitherValue(nn::PlayUsing,
@@ -421,8 +437,6 @@ void MainWindow::streamMedia()
}
}
-// Download media (to a file).
-
void MainWindow::downloadMedia()
{
QString fname = settings.value(nn::FilenameFormat).toString();
@@ -544,8 +558,6 @@ void MainWindow::downloadMedia()
}
}
-// Change program icon.
-
void MainWindow::changeProgramIcon()
{
#ifdef _1
@@ -569,8 +581,6 @@ void MainWindow::changeProgramIcon()
#endif // _1
}
-// Parse JSON data returned by quvi.
-
bool MainWindow::parseOK(QString& errmsg)
{
if (_proc->failed())
@@ -652,8 +662,6 @@ void MainWindow::onSettings()
}
}
-// Slot: About.
-
#define WWW "http://nomnom.sourceforge.net/"
void MainWindow::onAbout()
@@ -664,35 +672,13 @@ void MainWindow::onAbout()
#undef WWW
-// Slot: Recent.
-
void MainWindow::onRecent()
{
- const QStringList lst = recent.toStringList();
-
- if (lst.size() == 0)
- {
- nn::info(this, tr("No record of recently visited URLs found."));
- return;
- }
-
- bool ok = false;
- const QString s =
- QInputDialog::getItem(this,
- tr("Recent URLs"),
- tr("Select URL (most recent first):"),
- lst,
- 0,
- false,
- &ok);
- if (!ok)
- return;
-
- handleURL(s);
+ nn::NLogDialog *d = new nn::NLogDialog(this);
+ if (d->exec() == QDialog::Accepted)
+ handleURL(d->selected());
}
-// Slot: Download.
-
void MainWindow::onAddress()
{
const QString url =
@@ -704,8 +690,6 @@ void MainWindow::onAddress()
handleURL(url);
}
-// Slot: on feed.
-
void MainWindow::onFeed()
{
const QString p = settings.eitherValue(nn::FeedUsing,
@@ -735,15 +719,11 @@ void MainWindow::onFeed()
handleURL(d->selected());
}
-// Slot: quvi finished.
-
void MainWindow::onProcFinished(QString output)
{
_json = output;
}
-// Event: DragEnter.
-
void MainWindow::dragEnterEvent(QDragEnterEvent *e)
{
QUrl url(e->mimeData()->text());
@@ -751,8 +731,6 @@ void MainWindow::dragEnterEvent(QDragEnterEvent *e)
e->acceptProposedAction();
}
-// Event: Drop.
-
void MainWindow::dropEvent(QDropEvent *e)
{
handleURL(e->mimeData()->text().simplified());
diff --git a/src/log/nlogdialog.cpp b/src/log/nlogdialog.cpp
new file mode 100644
index 0000000..9fca6d4
--- /dev/null
+++ b/src/log/nlogdialog.cpp
@@ -0,0 +1,119 @@
+/* NomNom
+ * Copyright (C) 2011 Toni Gundogdu <le...@gm...>
+ *
+ * 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 <http://www.gnu.org/licenses/>.
+ */
+
+#include "config.h"
+
+#include <QCoreApplication>
+#include <QDialogButtonBox>
+#include <QMessageBox>
+#include <QVBoxLayout>
+#include <QToolBox>
+
+#include <NLogDialog>
+
+namespace nn
+{
+
+NLogDialog::NLogDialog(QWidget *parent/*=NULL*/)
+ : QDialog(parent), _toolbox(NULL)
+{
+
+// Toolbox
+
+ _toolbox = new QToolBox;
+
+ NLogRecent *recent = new NLogRecent;
+ connect(recent, SIGNAL(selected(QString)), this, SLOT(selected(QString)));
+
+ _toolbox->addItem(recent, tr("&Recent"));
+
+// Button box
+
+ QDialogButtonBox *bb = new QDialogButtonBox(
+ QDialogButtonBox::Ok | QDialogButtonBox::Cancel);
+
+ connect(bb, SIGNAL(accepted()), this, SLOT(accept()));
+ connect(bb, SIGNAL(rejected()), this, SLOT(reject()));
+
+// Layout
+
+ QVBoxLayout *box = new QVBoxLayout;
+ box->addWidget(_toolbox);
+ box->addWidget(bb);
+ setLayout(box);
+
+// Window
+
+ setMinimumSize(QSize(500,400));
+ setWindowTitle(tr("Log"));
+
+ foreachWidget();
+}
+
+void NLogDialog::foreachWidget()
+{
+ const int c = _toolbox->count();
+ for (int i=0; i<c; ++i)
+ {
+ NLogWidget *l = dynamic_cast<NLogWidget*>(_toolbox->widget(i));
+#ifdef _1
+ l->read();
+#endif
+ l->init();
+ }
+}
+
+void NLogDialog::done(int n)
+{
+ if (n == QDialog::Accepted)
+ {
+ if (_selected.isEmpty())
+ {
+ _toolbox->setCurrentIndex(0);
+ m_info(tr("Please select an item from the list"));
+ return;
+ }
+ }
+ QDialog::done(n);
+ close();
+}
+
+void NLogDialog::selected(QString s)
+{
+ _selected = s;
+}
+
+QString NLogDialog::selected() const
+{
+ return _selected;
+}
+
+void NLogDialog::m_info(const QString& msg)
+{
+ QMessageBox::information(this, QCoreApplication::applicationName(), msg);
+}
+
+// NLogWidget
+
+NLogWidget::NLogWidget(QWidget *parent/*=NULL*/)
+ : QWidget(parent)
+{
+}
+
+} // namespace nn
+
+/* vim: set ts=2 sw=2 tw=72 expandtab: */
diff --git a/src/log/nlogdialog.h b/src/log/nlogdialog.h
new file mode 100644
index 0000000..5635794
--- /dev/null
+++ b/src/log/nlogdialog.h
@@ -0,0 +1,87 @@
+/* NomNom
+ * Copyright (C) 2011 Toni Gundogdu <le...@gm...>
+ *
+ * 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 <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef nlogdialog_h
+#define nlogdialog_h
+
+#include <QDialog>
+
+class QTreeWidget;
+class QToolBox;
+
+namespace nn
+{
+
+class NLogDialog : public QDialog
+{
+ Q_OBJECT
+public:
+ NLogDialog(QWidget *parent=NULL);
+public:
+ QString selected() const;
+protected:
+ void done(int);
+private:
+ void m_info(const QString& msg);
+ void foreachWidget();
+private slots:
+ void selected(QString);
+private:
+ QToolBox *_toolbox;
+ QString _selected;
+};
+
+class NLogWidget : public QWidget
+{
+ Q_OBJECT
+public:
+ NLogWidget(QWidget *parent);
+protected:
+ virtual void init() = 0;
+#ifdef _1
+ virtual void read() = 0;
+#endif
+// Friends
+ friend class NLogDialog;
+};
+
+class NLogRecent : public NLogWidget
+{
+ Q_OBJECT
+public:
+ NLogRecent(QWidget *parent=NULL);
+signals:
+ void selected(QString);
+private slots:
+ void selected();
+ void reset();
+protected:
+ virtual void init();
+#ifdef _1
+ virtual void read();
+#endif
+private:
+ int confirmClear();
+private:
+ QTreeWidget *_treew;
+};
+
+} // namespace nn
+
+#endif
+
+/* vim: set ts=2 sw=2 tw=72 expandtab: */
diff --git a/src/log/nlogdialog_recent.cpp b/src/log/nlogdialog_recent.cpp
new file mode 100644
index 0000000..775ff94
--- /dev/null
+++ b/src/log/nlogdialog_recent.cpp
@@ -0,0 +1,108 @@
+/* NomNom
+ * Copyright (C) 2011 Toni Gundogdu <le...@gm...>
+ *
+ * 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 <http://www.gnu.org/licenses/>.
+ */
+
+#include "config.h"
+
+#include <QCoreApplication>
+#include <QDialogButtonBox>
+#include <QPushButton>
+#include <QVBoxLayout>
+#include <QTextStream>
+#include <QTreeWidget>
+#include <QMessageBox>
+
+#include <NRecentMutator>
+#include <NRecentEntry>
+#include <NLogDialog>
+
+extern nn::NRecentMutator recent;
+
+namespace nn
+{
+
+NLogRecent::NLogRecent(QWidget *parent/*=NULL*/)
+ : NLogWidget(parent), _treew(NULL)
+{
+
+// Widgets
+
+ _treew = new QTreeWidget;
+ _treew->setHeaderLabels(QStringList() << tr("Title") << tr("Added"));
+ _treew->setColumnCount(2);
+
+ connect(_treew, SIGNAL(itemSelectionChanged()), this, SLOT(selected()));
+
+ QDialogButtonBox *bb = new QDialogButtonBox(QDialogButtonBox::Reset);
+
+ connect(bb->button(QDialogButtonBox::Reset), SIGNAL(clicked()),
+ this, SLOT(reset()));
+
+// Layout
+
+ QVBoxLayout *box = new QVBoxLayout;
+ box->addWidget(_treew);
+ box->addWidget(bb);
+ setLayout(box);
+}
+
+#ifdef _1
+void NLogRecent::read()
+{
+ recent.read();
+}
+#endif
+
+void NLogRecent::init()
+{
+ recent.populate(_treew);
+ _treew->resizeColumnToContents(1);
+ _treew->sortByColumn(1);
+ _treew->setSortingEnabled(true);
+}
+
+void NLogRecent::selected()
+{
+ QTreeWidgetItem *i = _treew->selectedItems().first();
+ i = (i->childCount() > 0) ? i->child(0) : i;
+ if (i)
+ emit selected(i->text(0));
+}
+
+int NLogRecent::confirmClear()
+{
+ return QMessageBox::question(this,
+ qApp->applicationName(),
+ tr("All records will be lost permanently. "
+ "Really clear?"),
+ QMessageBox::Yes|QMessageBox::No);
+}
+
+void NLogRecent::reset()
+{
+ if (_treew->topLevelItemCount() == 0)
+ return;
+
+ if (confirmClear() != QMessageBox::Yes)
+ return;
+
+ _treew->clear();
+ recent.clear();
+}
+
+} // namespace nn
+
+/* vim: set ts=2 sw=2 tw=72 expandtab: */
diff --git a/src/log/nrecententry.cpp b/src/log/nrecententry.cpp
new file mode 100644
index 0000000..6827f22
--- /dev/null
+++ b/src/log/nrecententry.cpp
@@ -0,0 +1,85 @@
+/* NomNom
+ * Copyright (C) 2011 Toni Gundogdu <le...@gm...>
+ *
+ * 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 <http://www.gnu.org/licenses/>.
+ */
+
+#include "config.h"
+
+#include <NRecentEntry>
+
+namespace nn
+{
+
+NRecentEntry::NRecentEntry(QObject *parent/*=NULL*/)
+ : QObject(parent), _added(QDateTime::currentDateTime())
+{
+}
+
+NRecentEntry::NRecentEntry(const NRecentEntry& e, QObject *parent/*=NULL*/)
+ : QObject(parent)
+{
+ _copy(e);
+}
+
+NRecentEntry& NRecentEntry::operator=(const NRecentEntry& e)
+{
+ if (this != &e) _copy(e);
+ return *this;
+}
+
+void NRecentEntry::_copy(const NRecentEntry& e)
+{
+ _added = e.added();
+ _title = e.title();
+ _url = e.url();
+}
+
+NRecentEntry::~NRecentEntry()
+{
+}
+
+void NRecentEntry::setAdded(const QDateTime& d)
+{
+ _added = d;
+}
+
+QDateTime NRecentEntry::added() const
+{
+ return _added;
+}
+
+void NRecentEntry::setTitle(const QString& t)
+{
+ _title = t;
+}
+
+QString NRecentEntry::title() const
+{
+ return _title;
+}
+
+void NRecentEntry::setURL(const QString& u)
+{
+ _url = u;
+}
+
+QString NRecentEntry::url() const
+{
+ return _url;
+}
+
+} // namespace nn
+
+/* vim: set ts=2 sw=2 tw=72 expandtab: */
diff --git a/src/log/nrecententry.h b/src/log/nrecententry.h
new file mode 100644
index 0000000..82dcf6f
--- /dev/null
+++ b/src/log/nrecententry.h
@@ -0,0 +1,56 @@
+/* NomNom
+ * Copyright (C) 2011 Toni Gundogdu <le...@gm...>
+ *
+ * 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 <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef nrecententry_h
+#define nrecententry_h
+
+#include <QDateTime>
+
+namespace nn
+{
+
+class NRecentEntry : public QObject
+{
+ Q_OBJECT
+ Q_PROPERTY(QDateTime added READ added WRITE setAdded)
+ Q_PROPERTY(QString title READ title WRITE setTitle)
+ Q_PROPERTY(QString url READ url WRITE setURL)
+public:
+ NRecentEntry(QObject *parent=NULL);
+ NRecentEntry(const NRecentEntry&, QObject *parent=NULL);
+ NRecentEntry& operator=(const NRecentEntry&);
+ virtual ~NRecentEntry();
+public:
+ void setAdded(const QDateTime&);
+ void setTitle(const QString&);
+ void setURL(const QString&);
+ QDateTime added() const;
+ QString title() const;
+ QString url() const;
+private:
+ void _copy(const NRecentEntry&);
+private:
+ QDateTime _added;
+ QString _title;
+ QString _url;
+};
+
+} // namespace nn
+
+#endif
+
+/* vim: set ts=2 sw=2 tw=72 expandtab: */
diff --git a/src/log/nrecentmutator.cpp b/src/log/nrecentmutator.cpp
new file mode 100644
index 0000000..b29ac7b
--- /dev/null
+++ b/src/log/nrecentmutator.cpp
@@ -0,0 +1,156 @@
+/* NomNom
+ * Copyright (C) 2011 Toni Gundogdu <le...@gm...>
+ *
+ * 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 <http://www.gnu.org/licenses/>.
+ */
+
+#include "config.h"
+
+#include <QCoreApplication>
+#include <QTreeWidget>
+#include <QSettings>
+
+#ifdef ENABLE_VERBOSE
+#include <QDebug>
+#endif
+
+#include <qjson/qobjecthelper.h>
+#include <qjson/serializer.h>
+#include <qjson/parser.h>
+
+#include <NRecentMutator>
+#include <NRecentEntry>
+
+namespace nn
+{
+
+enum { MAX_ITEMS=10 };
+
+NRecentMutator::NRecentMutator()
+ : _maxItems(MAX_ITEMS)
+{
+}
+
+NRecentMutator& NRecentMutator::operator<<(const NRecentEntry& e)
+{
+ append(e);
+ return *this;
+}
+
+void NRecentMutator::setMaxItems(const int n)
+{
+ _maxItems = n;
+}
+
+void NRecentMutator::append(const NRecentEntry& e,
+ const bool ignoreLimit/*=false*/)
+{
+ foreach (const NRecentEntry *r, _entries)
+ {
+ if (r->url() == e.url())
+ return; // Found duplicate.
+ }
+
+ NRecentEntry *r = new NRecentEntry(e);
+ _entries.prepend(r);
+
+ if (!ignoreLimit && _entries.size() > _maxItems)
+ _entries.takeLast();
+
+#ifdef ENABLE_VERBOSE
+ qDebug() << __PRETTY_FUNCTION__ << __LINE__ << "size=" << _entries.size();
+#endif
+}
+
+void NRecentMutator::update(const NRecentEntry& e)
+{
+ foreach (NRecentEntry *r, _entries)
+ {
+ if (r->url() == e.url())
+ {
+ *r = e; // Update existing entry.
+ return;
+ }
+ }
+}
+
+void NRecentMutator::clear()
+{
+ _entries.clear();
+ write();
+}
+
+void NRecentMutator::write()
+{
+ QVariantList l;
+ foreach (const NRecentEntry *r, _entries)
+ {
+ l << QJson::QObjectHelper::qobject2qvariant(r);
+ }
+ QSettings s;
+ s.setValue("Recent/data", QJson::Serializer().serialize(l));
+}
+
+void NRecentMutator::read()
+{
+ _entries.clear();
+
+ QSettings s;
+ if (!s.contains("Recent/data"))
+ return;
+
+ QJson::Parser p;
+ bool ok;
+
+ QVariant d = p.parse(s.value("Recent/data").toByteArray(), &ok);
+ if (ok)
+ {
+ foreach (const QVariant v, d.toList())
+ {
+ NRecentEntry e;
+ QJson::QObjectHelper::qvariant2qobject(v.toMap(), &e);
+ append(e, true);
+ }
+ }
+}
+
+void NRecentMutator::for_each(foreach_callback fp)
+{
+ foreach (const NRecentEntry *r, _entries)
+ {
+ (fp)(*r);
+ }
+}
+
+void NRecentMutator::populate(QTreeWidget *w)
+{
+ w->clear();
+ foreach (const NRecentEntry *r, _entries)
+ {
+ const QString t = r->title();
+
+ QTreeWidgetItem *i = new QTreeWidgetItem(w);
+ i->setText(0, t.isEmpty()
+ ? qApp->translate("nn::NRecentMutator", "(no title)")
+ : t);
+ i->setText(1, r->added().toString(Qt::ISODate));
+
+ QTreeWidgetItem *j = new QTreeWidgetItem(i);
+ j->setText(0, r->url());
+ }
+}
+
+} // namespace nn
+
+/* vim: set ts=2 sw=2 tw=72 expandtab: */
diff --git a/src/Recent.h b/src/log/nrecentmutator.h
similarity index 52%
rename from src/Recent.h
rename to src/log/nrecentmutator.h
index 37f971f..1196f7c 100644
--- a/src/Recent.h
+++ b/src/log/nrecentmutator.h
@@ -1,6 +1,5 @@
-/*
- * NomNom
- * Copyright (C) 2010 Toni Gundogdu <le...@gm...>
+/* NomNom
+ * Copyright (C) 2011 Toni Gundogdu <le...@gm...>
*
* 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
@@ -16,32 +15,41 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
-#ifndef nomnom_recent_h
-#define nomnom_recent_h
+#ifndef nrecentmutator_h
+#define nrecentmutator_h
-#include <QStringList>
+#include <QList>
-class Recent
+class QTreeWidget;
+
+namespace nn
+{
+
+class NRecentEntry;
+
+class NRecentMutator
{
public:
- Recent ();
- virtual ~Recent();
-public:
- void setMaxItems(const int);
-public:
- void write () const;
- void read ();
- void append(const QString&);
- void clear ();
+ NRecentMutator();
+ NRecentMutator& operator<<(const NRecentEntry&);
public:
- QStringList toStringList () const;
+ typedef void (*foreach_callback)(const NRecentEntry&);
public:
- Recent& operator<< (const QString&);
+ void setMaxItems(const int);
+ void append(const NRecentEntry&, const bool ignoreLimit=false);
+ void update(const NRecentEntry&);
+ void for_each(foreach_callback);
+ void populate(QTreeWidget*);
+ void write();
+ void clear();
+ void read();
private:
- QStringList drops;
- int maxItems;
+ QList<NRecentEntry*> _entries;
+ int _maxItems;
};
+} // namespace nn
+
#endif
-// vim: set ts=2 sw=2 tw=72 expandtab:
+/* vim: set ts=2 sw=2 tw=72 expandtab: */
diff --git a/src/main.cpp b/src/main.cpp
index 0a2a8e2..c22bfa0 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -30,25 +30,22 @@
#endif
#include <NSettingsMutator>
+#include <NRecentMutator>
#include <NDetectDialog>
#include <NSysTray>
#include <NFeed>
#include <NLang>
-#include "Recent.h"
-// UI:
#include "MainWindow.h"
-using namespace nn;
-
bool have_quvi_feature_query_formats = false;
bool have_umph_feature_all = false;
-NSettingsMutator settings;
-feed::NFeedList feedItems;
-NSysTray *systray = NULL;
-Recent recent;
+nn::NSettingsMutator settings;
+nn::feed::NFeedList feedItems;
+nn::NSysTray *systray = NULL;
+nn::NRecentMutator recent;
-static void set_value(const SettingKey k, const detect::NResult& r)
+static void set_value(const nn::SettingKey k, const nn::detect::NResult& r)
{
settings.setValue(k, QString("%1%2%3")
.arg(r.first)
@@ -58,13 +55,13 @@ static void set_value(const SettingKey k, const detect::NResult& r)
static void first_run(QSettings& s)
{
- NDetectDialog *d = new NDetectDialog;
+ nn::NDetectDialog *d = new nn::NDetectDialog;
d->showModeComboBox(false);
d->exec();
- set_value(DownloadUsing, d->downloader());
- set_value(ParseUsing, d->mediaParser());
- set_value(PlayUsing, d->mediaPlayer());
- set_value(FeedUsing, d->feedParser());
+ set_value(nn::DownloadUsing, d->downloader());
+ set_value(nn::ParseUsing, d->mediaParser());
+ set_value(nn::PlayUsing, d->mediaPlayer());
+ set_value(nn::FeedUsing, d->feedParser());
s.setValue("FirstRun", false);
settings.write();
}
@@ -96,10 +93,10 @@ static void print_nresults(const nn::DetectType n, const QString& s)
static bool print_cmds()
{
std::clog << "Detect commands from $PATH..." << std::endl;
- print_nresults(MediaParser, "Media parsers:");
- print_nresults(MediaPlayer, "Media players:");
- print_nresults(FeedParser, "Feed parsers:");
- print_nresults(Downloader, "Downloaders:");
+ print_nresults(nn::MediaParser, "Media parsers:");
+ print_nresults(nn::MediaPlayer, "Media players:");
+ print_nresults(nn::FeedParser, "Feed parsers:");
+ print_nresults(nn::Downloader, "Downloaders:");
}
static bool print_locale()
@@ -239,10 +236,10 @@ int main(int argc, char *argv[])
s.beginGroup("Settings"); // settings/nsettingsmutator.cpp
if (s.contains("Language"))
- r = lang::choose(s.value("Language").toString());
+ r = nn::lang::choose(s.value("Language").toString());
if (!r) // Use system locale.
- lang::choose();
+ nn::lang::choose();
// Detect commands if this is a first run.
@@ -259,7 +256,6 @@ int main(int argc, char *argv[])
// Window.
MainWindow *w = new MainWindow;
- recent.read();
return app.exec();
}
-----------------------------------------------------------------------
Summary of changes:
src/Makefile.am | 64 +++++---
src/NLogDialog | 1 +
src/NRecentEntry | 1 +
src/NRecentMutator | 1 +
src/Recent.cpp | 72 ---------
src/Recent.h | 47 ------
src/i/MainWindow.cpp | 94 +++++-------
src/log/nlogdialog.cpp | 116 +++++++++++++++
src/{about/naboutdialog.h => log/nlogdialog.h} | 52 ++++++-
src/log/nlogdialog_recent.cpp | 104 +++++++++++++
src/{feed/nfeed.cpp => log/nrecententry.cpp} | 79 +++++++----
.../nfeedprogressdialog.h => log/nrecententry.h} | 48 +++----
src/log/nrecentmutator.cpp | 156 ++++++++++++++++++++
.../nsettingsmutator.h => log/nrecentmutator.h} | 32 +++--
src/main.cpp | 38 ++---
15 files changed, 610 insertions(+), 295 deletions(-)
create mode 100644 src/NLogDialog
create mode 100644 src/NRecentEntry
create mode 100644 src/NRecentMutator
delete mode 100644 src/Recent.cpp
delete mode 100644 src/Recent.h
create mode 100644 src/log/nlogdialog.cpp
copy src/{about/naboutdialog.h => log/nlogdialog.h} (52%)
create mode 100644 src/log/nlogdialog_recent.cpp
copy src/{feed/nfeed.cpp => log/nrecententry.cpp} (50%)
copy src/{feed/nfeedprogressdialog.h => log/nrecententry.h} (54%)
create mode 100644 src/log/nrecentmutator.cpp
copy src/{settings/nsettingsmutator.h => log/nrecentmutator.h} (62%)
repo.or.cz automatic notification. Contact project admin le...@gm...
if you want to unsubscribe, or site admin ad...@re... if you receive
no reply.
--
nomnom.git ("The graphical media download tool")
|