cfgcustomservers.h
1 //------------------------------------------------------------------------------
2 // cfgcustomservers.cpp
3 //------------------------------------------------------------------------------
4 //
5 // This library is free software; you can redistribute it and/or
6 // modify it under the terms of the GNU Lesser General Public
7 // License as published by the Free Software Foundation; either
8 // version 2.1 of the License, or (at your option) any later version.
9 //
10 // This library 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 GNU
13 // Lesser General Public License for more details.
14 //
15 // You should have received a copy of the GNU Lesser General Public
16 // License along with this library; if not, write to the Free Software
17 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
18 // 02110-1301 USA
19 //
20 //------------------------------------------------------------------------------
21 // Copyright (C) 2009 "Zalewa" <zalewapl@gmail.com>
22 //------------------------------------------------------------------------------
23 #ifndef __CFGCUSTOMSERVERS_H_
24 #define __CFGCUSTOMSERVERS_H_
25 
26 #include "dptr.h"
27 #include "gui/configuration/configpage.h"
28 #include <QIcon>
29 
30 class CustomServerInfo;
31 class EnginePlugin;
32 class QModelIndex;
33 class QStandardItem;
34 class QStandardItemModel;
35 
37 {
38  Q_OBJECT
39 
40 public:
41  CFGCustomServers(QWidget *parent = nullptr);
42  ~CFGCustomServers() override;
43 
44  QIcon icon() const override
45  {
46  return QIcon(":/flags/localhost-small");
47  }
48  QString name() const override
49  {
50  return tr("Pinned servers");
51  }
52 
53 protected:
54  void readSettings() override;
55  void saveSettings() override;
56 
57 private:
58  enum CheckAndFixPorts
59  {
60  AllOk,
61  AtLeastOneFixed
62  };
63 
64  enum ColumnIndices
65  {
66  EngineColumnIndex = 0,
67  AddressColumnIndex = 1,
68  PortColumnIndex = 2,
69  EnabledIndex = 3
70  };
71 
73 
81  CheckAndFixPorts checkAndFixPorts(int firstRow, int lastRow);
82  const EnginePlugin *getPluginInfoForRow(int rowIndex);
83  bool isPortColumnWithinRange(int leftmostColumnIndex, int rightmostColumnIndex);
84  bool isPortCorrect(int rowIndex);
85 
86  void prepareEnginesComboBox();
87  void prepareTable();
88  void setEnabledOnSelected(bool enabled);
89  void setEngineOnItem(QStandardItem *, const QString &engineName);
90  void setPortToDefault(int rowIndex);
91 
92  QVector<CustomServerInfo> tableGetServers();
93 
94 private slots:
95  void add();
96  void add(const QString &engineName, const QString &host,
97  unsigned short port, bool enabled);
98  void dataChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight);
99  void disableSelected();
100  void enableSelected();
101  void remove();
102  void setEngine();
103 };
104 
105 #endif