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 <QObject>
13 #include <QDialog>
14 #include <QAbstractItemModel>
15 
16 #include "ui_UIUserCommands.h"
17 
18 #include "dcpp/stdinc.h"
19 #include <dcpp/FavoriteManager.h>
20 
21 class UCDialog: public QDialog, public Ui::UIUserCommands{
22 Q_OBJECT
23 
24 public:
25     UCDialog(QWidget *parent = NULL);
26 
27     unsigned long getCtx()  const;
28     unsigned long getType();
29 
30     QString getName() const;
31     QString getHub()  const;
32     QString getCmd()  const;
33 
34     int type;
35 
36 public Q_SLOTS:
37     void updateLines();
38     void updateType();
39 };
40 
41 class UCItem{
42 
43 public:
44 
45     UCItem(UCItem *parent = NULL);
46     ~UCItem();
47 
48     void appendChild(UCItem *child);
49 
50     UCItem *child(int row);
51     int childCount() const;
52     int columnCount() const;
53     int row() const;
54     UCItem *parent();
55 
56     QList<UCItem*> childItems;
57 
58     QString name;
59     QString comm;
60     QString hub;
61     QString to;
62     unsigned long ctx;
63     unsigned long type;
64     unsigned long id;
65 private:
66     UCItem *parentItem;
67 };
68 
69 class UCModel : public QAbstractItemModel
70 {
71 Q_OBJECT
72 public:
73     explicit UCModel(QObject *parent = 0);
74     virtual ~UCModel();
75 
76     /** */
77     QVariant data(const QModelIndex &, int) const;
78     /** */
79     Qt::ItemFlags flags(const QModelIndex &) const;
80     /** */
81     QVariant headerData(int section, Qt::Orientation, int role = Qt::DisplayRole) const;
82     /** */
83     QModelIndex index(int, int, const QModelIndex &parent = QModelIndex()) const;
84     /** */
85     QModelIndex parent(const QModelIndex &index) const;
86     /** */
87     int rowCount(const QModelIndex &parent = QModelIndex()) const;
88     /** */
89     int columnCount(const QModelIndex &parent = QModelIndex()) const;
90     /** sort list */
91     virtual void sort(int column, Qt::SortOrder order = Qt::AscendingOrder);
92 
93     void loadUC();
94     void addUC(const dcpp::UserCommand &cmd);
95 
96 signals:
97     void selectIndex(const QModelIndex&);
98 
99 public slots:
100     void newUC();
101     void changeUC(const QModelIndex&);
102     void remUC(const QModelIndex&);
103     void moveUp(const QModelIndex&);
104     void moveDown(const QModelIndex&);
105 
106 private:
107     void initDlgFromItem(UCDialog&, const UCItem&);
108 
109     UCItem *rootItem;
110 };
111