1 /***************************************************************************
2 *                                                                         *
3 *   This program is free software; you can redistribute it and/or modify  *
4 *   it under the terms of the GNU General Public License as published by  *
5 *   the Free Software Foundation; either version 3 of the License, or     *
6 *   (at your option) any later version.                                   *
7 *                                                                         *
8 ***************************************************************************/
9 
10 #pragma once
11 
12 #include <QWidget>
13 #include <QMap>
14 #include <QCloseEvent>
15 #include <QMetaType>
16 
17 #include "ui_UIFavoriteHubs.h"
18 #include "ui_UIFavoriteHubEditor.h"
19 #include "ArenaWidget.h"
20 #include "WulforUtil.h"
21 
22 #include "dcpp/stdinc.h"
23 #include "dcpp/Singleton.h"
24 #include "dcpp/FavoriteManager.h"
25 #include "dcpp/FavoriteManagerListener.h"
26 
27 class FavoriteHubModel;
28 class FavoriteHubItem;
29 
30 using namespace dcpp;
31 
32 class FavoriteHubEditor:
33         public QDialog,
34         public Ui::UIFavoriteHubEditor
35 {
36     Q_OBJECT
37 
38     public:
39         FavoriteHubEditor(QWidget *parent = NULL):
QDialog(parent)40                 QDialog(parent)
41         {
42             setupUi(this);
43         }
44 };
45 
46 class FavoriteHubs :
47         public QWidget,
48         private Ui::UIFavoriteHubs,
49         public ArenaWidget,
50         private dcpp::FavoriteManagerListener,
51         public dcpp::Singleton<FavoriteHubs>
52 {
53     Q_OBJECT
54     Q_INTERFACES(ArenaWidget)
55 
56     friend class dcpp::Singleton<FavoriteHubs>;
57 
58     typedef QMap<QString,QVariant> StrMap;
59 public:
60     QWidget *getWidget();
61     QString getArenaTitle();
62     QString getArenaShortTitle();
63     QMenu *getMenu();
getPixmap()64     const QPixmap &getPixmap(){ return WICON(WulforUtil::eiFAVSERVER); }
role()65     ArenaWidget::Role role() const { return ArenaWidget::FavoriteHubs; }
66 
67 protected:
68     virtual void closeEvent(QCloseEvent *);
69 
70 private Q_SLOTS:
71     void slotContexMenu(const QPoint&);
72     void slotClicked(const QModelIndex&);
73     void slotDblClicked();
74     void slotHeaderMenu();
75 
76     void slotSettingsChanged(const QString &key, const QString &value);
77 
78     void slotAdd_newButtonClicked();
79     void slotChangeButtonClicked();
80     void slotRemoveButtonClicked();
81     void slotConnectButtonClicked();
82     void slotUpdateComboBox_CID();
83 
84 private:
85     FavoriteHubs(QWidget* = NULL);
86     virtual ~FavoriteHubs();
87 
88     void load();
89     void save();
90 
91     void init();
92     void initHubEditor(FavoriteHubEditor &);
93     void initHubEditor(FavoriteHubEditor &, StrMap&);
94     /** Init StrMap for importing into the FavoriteHubEditor */
95     void getParams(const FavoriteHubEntry*, StrMap&);
96     /** Init StrMap for importing into the FavoriteHubEntry */
97     void getParams(const FavoriteHubEditor&, StrMap&);
98     void updateEntry(FavoriteHubEntry&, StrMap&);
99     void updateItem(FavoriteHubItem*, StrMap&);
100 
101     FavoriteHubItem *getItem();
102 
103     FavoriteHubModel *model;
104 
105     QStringList fakeNMDCTags;
106     QStringList fakeADCTags;
107 
108     virtual void on(FavoriteAdded, const FavoriteHubEntryPtr) noexcept;
109     virtual void on(FavoriteRemoved, const FavoriteHubEntryPtr) noexcept;
110 };
111 
112 Q_DECLARE_METATYPE (FavoriteHubs*)
113