client: Fix Local Highlights import to remote
[quassel.git] / src / qtui / settingspages / corehighlightsettingspage.h
1 /***************************************************************************
2  *   Copyright (C) 2005-2018 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 <QVariantList>
24 #include <QTableWidgetItem>
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() override;
44     void load() override;
45     void defaults() 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, const QString &name = tr("highlight rule"), bool regex = false,
53                             bool cs = false, const QString &sender = "", const QString &chanName = "",
54                             bool self = false);
55     void addNewIgnoredRow(bool enable = true, const QString &name = tr("highlight rule"), bool regex = false,
56                           bool cs = false, const QString &sender = "", const QString &chanName = "", bool self = false);
57     void removeSelectedHighlightRows();
58     void removeSelectedIgnoredRows();
59     void highlightNicksChanged(const int index);
60     void selectHighlightRow(QTableWidgetItem *item);
61     void selectIgnoredRow(QTableWidgetItem *item);
62     void highlightTableChanged(QTableWidgetItem *item);
63     void ignoredTableChanged(QTableWidgetItem *item);
64
65     /** Import local Highlight rules into the Core Highlight rules
66      *
67      * Iterates through all local highlight rules, converting each into core-side highlight rules.
68      */
69     void importRules();
70
71 private:
72     Ui::CoreHighlightSettingsPage ui;
73
74     HighlightRuleManager::HighlightRuleList highlightList;
75     HighlightRuleManager::HighlightRuleList ignoredList;
76
77     enum column {
78         EnableColumn = 0,
79         NameColumn = 1,
80         RegExColumn = 2,
81         CsColumn = 3,
82         SenderColumn = 4,
83         ChanColumn = 5,
84         ColumnCount = 6
85     };
86
87     void emptyHighlightTable();
88     void emptyIgnoredTable();
89
90     void setupRuleTable(QTableWidget *highlightTable) const;
91
92     bool _initialized;
93 };