aboutsummaryrefslogtreecommitdiffstats
path: root/SQLiteStudio3/guiSQLiteStudio/windows/bugreporthistorywindow.cpp
blob: c92f6f411a3fc00e6ad368e261af6456d8ecddf0 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
#include "bugreporthistorywindow.h"
#include "ui_bugreporthistorywindow.h"
#include "common/unused.h"
#include "services/config.h"
#include <QDebug>
#include <QLabel>

CFG_KEYS_DEFINE(BugReportHistoryWindow)

BugReportHistoryWindow::BugReportHistoryWindow(QWidget *parent) :
    MdiChild(parent),
    ui(new Ui::BugReportHistoryWindow)
{
    init();
}

BugReportHistoryWindow::~BugReportHistoryWindow()
{
    delete ui;
}

bool BugReportHistoryWindow::restoreSessionNextTime()
{
    return false;
}

QVariant BugReportHistoryWindow::saveSession()
{
    return QVariant();
}

bool BugReportHistoryWindow::restoreSession(const QVariant& sessionValue)
{
    UNUSED(sessionValue);
    return false;
}

Icon* BugReportHistoryWindow::getIconNameForMdiWindow()
{
    return ICONS.BUG_LIST;
}

QString BugReportHistoryWindow::getTitleForMdiWindow()
{
    return tr("Reports history");
}

void BugReportHistoryWindow::createActions()
{
    createAction(CLEAR_HISTORY, ICONS.CLEAR_HISTORY, tr("Clear reports history"), this, SLOT(clearHistory()), ui->toolBar);
    createAction(DELETE_SELECTED, ICONS.DELETE_ROW, tr("Delete selected entry"), this, SLOT(deleteSelected()), ui->toolBar);
}

void BugReportHistoryWindow::setupDefShortcuts()
{
    setShortcutContext({
                           DELETE_SELECTED
                       },
                       Qt::WidgetWithChildrenShortcut);

    BIND_SHORTCUTS(BugReportHistoryWindow, Action);
}

QToolBar* BugReportHistoryWindow::getToolBar(int toolbar) const
{
    UNUSED(toolbar);
    return ui->toolBar;
}

void BugReportHistoryWindow::init()
{
    ui->setupUi(this);
    initActions();

    reload();
    connect(ui->reportsList->selectionModel(), SIGNAL(selectionChanged(QItemSelection,QItemSelection)), this, SLOT(updateState()));
    connect(CFG, SIGNAL(reportsHistoryRefreshNeeded()), this, SLOT(reload()));

    updateState();
}

void BugReportHistoryWindow::updateState()
{
    actionMap[DELETE_SELECTED]->setEnabled(ui->reportsList->selectedItems().size() > 0);
}

void BugReportHistoryWindow::reload()
{
    static_qstring(urlTpl, "<a href=\"%1\">%2</a>");
    QString invalidUrlTpl = tr("Invalid response from server.");

    QList<Config::ReportHistoryEntryPtr> entries = CFG->getReportHistory();
    ui->reportsList->clear();
    ui->reportsList->setRowCount(entries.size());

    QTableWidgetItem* item = nullptr;
    QLabel* urlLabel = nullptr;
    int row = 0;
    for (const Config::ReportHistoryEntryPtr& entry : entries)
    {
        item = new QTableWidgetItem((entry->isFeatureRequest ? ICONS.FEATURE_REQUEST : ICONS.BUG), entry->title);
        item->setData(ENTRY_ID, entry->id);
        ui->reportsList->setItem(row, 0, item);

        item = new QTableWidgetItem(QDateTime::fromTime_t(entry->timestamp).toString("yyyy-MM-dd HH:mm:ss"));
        ui->reportsList->setItem(row, 1, item);

        if (entry->url.startsWith("http://"))
            urlLabel = new QLabel(urlTpl.arg(entry->url, entry->url));
        else
            urlLabel = new QLabel(invalidUrlTpl);

        urlLabel->setOpenExternalLinks(true);
        ui->reportsList->setCellWidget(row, 2, urlLabel);

        row++;
    }

    ui->reportsList->setHorizontalHeaderLabels({tr("Title"), tr("Reported at"), tr("URL")});
    ui->reportsList->resizeColumnsToContents();
}

void BugReportHistoryWindow::clearHistory()
{
    CFG->clearReportHistory();
}

void BugReportHistoryWindow::deleteSelected()
{
    QList<QTableWidgetItem*> items = ui->reportsList->selectedItems();
    if (items.size() == 0)
    {
        qDebug() << "Called BugReportHistoryWindow::deleteSelected(), but there's no row selected.";
        return;
    }

    int id = items.first()->data(ENTRY_ID).toInt();
    if (id == 0)
    {
        qDebug() << "Called BugReportHistoryWindow::deleteSelected(), but there's no ID in selected row.";
        return;
    }

    CFG->deleteReport(id);
}

bool BugReportHistoryWindow::isUncommited() const
{
    return false;
}

QString BugReportHistoryWindow::getQuitUncommitedConfirmMessage() const
{
    return QString();
}