Debian Codegraph @

src/gui/ImgurHistoryDialog.cpp

raw symbols SCIP
1 /*
2 * Copyright (C) 2019 Damir Porobic <[email protected]>
3 *
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 2 of the License, or
7 * (at your option) any later version.
8 *
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.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin Street, Fifth Floor,
17 * Boston, MA 02110-1301, USA.
18 */
19
20 #include "ImgurHistoryDialog.h"
21
22 ImgurHistoryDialog::ImgurHistoryDialog()
23 {
24 setWindowTitle(QApplication::applicationName() + QLatin1String(" - ") + tr("Imgur History"));
25 setMinimumWidth(650);
26 setMinimumHeight(400);
27
28 ImgurResponseLogger imgurResponseLogger;
29 auto logEntries = imgurResponseLogger.getLogs();
30
31 createTable(logEntries.count());
32
33 populateTable(logEntries);
34
35 mCloseButton = new QPushButton(tr("Close"));
36 connect(mCloseButton, &QPushButton::clicked, this, &QDialog::close);
37
38 mLayout = new QVBoxLayout;
39 mLayout->addWidget(mTableWidget);
40 mLayout->addWidget(mCloseButton);
41 mLayout->setAlignment(Qt::AlignRight);
42 setLayout(mLayout);
43 }
44
45
46 ImgurHistoryDialog::~ImgurHistoryDialog()
47 {
48 delete mTableWidget;
49 delete mLayout;
50 delete mCloseButton;
51 }
52
53 void ImgurHistoryDialog::createTable(int rowCount)
54 {
55 mTableWidget = new QTableWidget(rowCount, 3, this);
56 mTableWidget->setHorizontalHeaderLabels(QStringList{ tr("Time Stamp"), tr("Link"), tr("Delete Link") });
57 auto header = mTableWidget->horizontalHeader();
58 header->setStretchLastSection(true);
59
60 connect(mTableWidget, &QTableWidget::cellClicked, this, &ImgurHistoryDialog::cellClicked);
61 }
62
63 void ImgurHistoryDialog::populateTable(const QStringList &logEntries)
64 {
65 for (const auto &entry : logEntries) {
66 addEntryToTable(entry, logEntries.indexOf(entry));
67 }
68 mTableWidget->resizeColumnsToContents();
69 }
70
71 void ImgurHistoryDialog::addEntryToTable(const QString &entry, int row) const
72 {
73 auto cells = entry.split(QLatin1String(","));
74 auto dateCell = new QTableWidgetItem(cells[0]);
75 auto linkCell = new QTableWidgetItem(cells[1]);
76 auto deleteLinkCell = new QTableWidgetItem(cells[2]);
77 mTableWidget->setItem(row, 0, dateCell);
78 mTableWidget->setItem(row, 1, linkCell);
79 mTableWidget->setItem(row, 2, deleteLinkCell);
80 }
81
82 void ImgurHistoryDialog::cellClicked(int row, int column) const
83 {
84 if (column == 1 || column == 2) {
85 auto cell = mTableWidget->item(row, column);
86 QDesktopServices::openUrl(cell->text());
87 }
88 }