common: Make SyncableObject non-copyable
[quassel.git] / src / qtui / settingspages / corehighlightsettingspage.h
1 /***************************************************************************
2  *   Copyright (C) 2005-2020 by the Quassel Project                        *
3  *   devel@quassel-irc.org                                                 *
4  *                                                                         *
5  *   This program is free software; you can redistribute it and/or modify  *
6  *   it under the terms of the GNU General Public License as published by  *
7  *   the Free Software Foundation; either version 2 of the License, or     *
8  *   (at your option) version 3.                                           *
9  *                                                                         *
10  *   This program is distributed in the hope that it will be useful,       *
11  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
12  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
13  *   GNU General Public License for more details.                          *
14  *                                                                         *
15  *   You should have received a copy of the GNU General Public License     *
16  *   along with this program; if not, write to the                         *
17  *   Free Software Foundation, Inc.,                                       *
18  *   51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.         *
19  ***************************************************************************/
20
21 #pragma once
22
23 #include <QTableWidgetItem>
24 #include <QVariantList>
25
26 #include "highlightrulemanager.h"
27 #include "settingspage.h"
28
29 #include "ui_corehighlightsettingspage.h"
30
31 class CoreHighlightSettingsPage : public SettingsPage
32 {
33     Q_OBJECT
34
35 public:
36     explicit CoreHighlightSettingsPage(QWidget* parent = nullptr);
37
38     bool hasDefaults() const override;
39
40     bool isSelectable() const override;
41
42 public slots:
43     void save() final override;
44     void load() final override;
45     void defaults() final override;
46     void revert();
47     void clientConnected();
48
49 private slots:
50     void coreConnectionStateChanged(bool state);
51     void widgetHasChanged();
52     void addNewHighlightRow(bool enable = true,
53                             int id = -1,
54                             const QString& name = tr("highlight rule"),
55                             bool regex = false,
56                             bool cs = false,
57                             const QString& sender = "",
58                             const QString& chanName = "",
59                             bool self = false);
60     void addNewIgnoredRow(bool enable = true,
61                           int id = -1,
62                           const QString& name = tr("highlight rule"),
63                           bool regex = false,
64                           bool cs = false,
65                           const QString& sender = "",
66                           const QString& chanName = "",
67                           bool self = false);
68     void removeSelectedHighlightRows();
69     void removeSelectedIgnoredRows();
70     void highlightNicksChanged(int index);
71     void selectHighlightRow(QTableWidgetItem* item);
72     void selectIgnoredRow(QTableWidgetItem* item);
73     void highlightTableChanged(QTableWidgetItem* item);
74     void ignoredTableChanged(QTableWidgetItem* item);
75
76     /** Import local Highlight rules into the Core Highlight rules
77      *
78      * Iterates through all local highlight rules, converting each into core-side highlight rules.
79      */
80     void importRules();
81
82     /**
83      * Event handler for core unspported Details button
84      */
85     void on_coreUnsupportedDetails_clicked();
86
87 private:
88     Ui::CoreHighlightSettingsPage ui;
89
90     HighlightRuleManager::HighlightRuleList highlightList;
91     HighlightRuleManager::HighlightRuleList ignoredList;
92
93     enum column
94     {
95         EnableColumn = 0,
96         NameColumn = 1,
97         RegExColumn = 2,
98         CsColumn = 3,
99         SenderColumn = 4,
100         ChanColumn = 5,
101         ColumnCount = 6
102     };
103
104     void emptyHighlightTable();
105     void emptyIgnoredTable();
106
107     void setupRuleTable(QTableWidget* highlightTable) const;
108
109     /**
110      * Get tooltip for the specified rule table column
111      *
112      * @param tableColumn Column to retrieve tooltip
113      * @return Translated tooltip for the specified column
114      */
115     QString getTableTooltip(column tableColumn) const;
116
117     /**
118      * Setup tooltips and "What's this?" prompts for table entries
119      *
120      * @param enableWidget  Enabled checkbox
121      * @param nameWidget    Rule name
122      * @param regExWidget   RegEx enabled
123      * @param csWidget      Case-sensitive
124      * @param senderWidget  Sender name
125      * @param chanWidget    Channel name
126      */
127     void setupTableTooltips(
128         QWidget* enableWidget, QWidget* nameWidget, QWidget* regExWidget, QWidget* csWidget, QWidget* senderWidget, QWidget* chanWidget) const;
129
130     /**
131      * Setup tooltips and "What's this?" prompts for table entries
132      *
133      * @param enableWidget  Enabled checkbox
134      * @param nameWidget    Rule name
135      * @param regExWidget   RegEx enabled
136      * @param csWidget      Case-sensitive
137      * @param senderWidget  Sender name
138      * @param chanWidget    Channel name
139      */
140     void setupTableTooltips(QTableWidgetItem* enableWidget,
141                             QTableWidgetItem* nameWidget,
142                             QTableWidgetItem* regExWidget,
143                             QTableWidgetItem* csWidget,
144                             QTableWidgetItem* senderWidget,
145                             QTableWidgetItem* chanWidget) const;
146
147     /** Update the UI to show core support for highlights
148      *
149      * Shows or hides the UI warnings around core-side highlights according to core connection and
150      * core feature support.
151      *
152      * @param state  True if connected to core, otherwise false
153      */
154     void updateCoreSupportStatus(bool state);
155
156     int nextId();
157
158     bool _initialized;
159 };