NLogRecent: Move Reset button to NLogDialog button box
[nomnom.git] / src / log / nlogdialog_recent.cpp
blobd884cf0c30c9ed27e6e21b3856544a01c3b92663
1 /* NomNom
2 * Copyright (C) 2011 Toni Gundogdu <legatvs@gmail.com>
4 * This program is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation, either version 3 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program. If not, see <http://www.gnu.org/licenses/>.
18 #include "config.h"
20 #include <QCoreApplication>
21 #include <QDialogButtonBox>
22 #include <QVBoxLayout>
23 #include <QTextStream>
24 #include <QTreeWidget>
25 #include <QMessageBox>
27 #include <NRecentMutator>
28 #include <NRecentEntry>
29 #include <NLogDialog>
30 #include <NSettings>
31 #include <NUtil>
33 extern nn::NRecentMutator recent;
35 namespace nn
38 NLogRecent::NLogRecent(QWidget *parent/*=NULL*/)
39 : NLogWidget(parent), _treew(NULL)
42 // Widgets
44 _treew = new QTreeWidget;
45 _treew->setHeaderLabels(QStringList() << tr("Title") << tr("Added"));
46 _treew->setColumnCount(2);
48 connect(_treew, SIGNAL(itemSelectionChanged()), this, SLOT(selected()));
50 // Layout
52 QVBoxLayout *box = new QVBoxLayout;
53 box->addWidget(_treew);
54 setLayout(box);
57 #ifdef _1
58 void NLogRecent::read()
60 recent.read();
62 #endif
64 void NLogRecent::init()
66 recent.populate(_treew);
67 _treew->resizeColumnToContents(0);
68 _treew->sortByColumn(1);
69 _treew->setSortingEnabled(true);
72 void NLogRecent::selected()
74 QTreeWidgetItem *i = _treew->selectedItems().first();
75 i = (i->childCount() > 0) ? i->child(0) : i;
76 if (i)
77 emit selected(i->text(0));
80 void NLogRecent::reset()
82 if (_treew->topLevelItemCount() == 0)
83 return;
85 if (ask(this, tr("All records will be lost permanently. Really clear?"))
86 != QMessageBox::Yes)
88 return;
91 _treew->clear();
92 recent.clear();
95 } // namespace nn
97 /* vim: set ts=2 sw=2 tw=72 expandtab: */