summaryrefslogtreecommitdiffstats
path: root/src/dialog.h
blob: ea042cd47849db179d8b9c591e42da9916d3b721 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
#ifndef DIALOG_H
#define DIALOG_H

#include <QDialog>
#include <QModelIndex>
#include <QList>
#include <QSettings>
#include <QNetworkReply>
#include <QKeyEvent>

#include "session.h"
#include "sessiontreemodel.h"
#include "sessionsiconholder.h"


namespace Ui {
    class Dialog;
}
class QTimer;

class Dialog : public QDialog {
    Q_OBJECT
  private: // Constants
    static const int STR_LOADING = 0;
    static const int STR_URL_ERROR = 1;
    static const int STR_NO_ITEMS = 2;
    static const int STR__MAX = 3;
    static const int TAB_NATIVE = 0;
    static const int TAB_MY_COURSES = 1;
    static const int TAB_ALL_VMS = 2;
    static const int TAB_COUNT = 3;
  public: // Public methods
    explicit Dialog(int defaultTab = -1, bool examMode = false, QWidget *parent = 0);
    ~Dialog();
    void addItems(const QList<Session*>&, int tab);
    void addStatusString(const int status);
    void removeStatusString(const int status);
    bool selectSession(const QString& name);
    bool selectSessionByUuid(const QString& name);
    void selectPreviousSession();
    void setTheme();
    void startSession(const QString& name);

  protected: // Overrides
    void changeEvent(QEvent *e);
    void mousePressEvent(QMouseEvent *event);

  private: // Private vars n methods
    Ui::Dialog *ui;
    SessionTreeModel *model_[TAB_COUNT];
    QPushButton *tabs_[TAB_COUNT];
    QPoint oldCenter_;
    QTimer *centerTimer_;
    QString autoStartEntry_;
    int activeTab_;
    int defaultTab_;
    bool userInteracted_;
    bool genericExpandedOnce_;
    bool examMode_;
    QString strings_[STR__MAX];
    void onTabButtonChanged(int tab);
    void configClearButton();
    void setListModel(SessionTreeModel *model);
    void keyPressEvent(QKeyEvent * e);
    void selectFirstElement();

    void checkAutostart();

  private slots:
    void on_pushButtonStart_clicked();
    void on_pushButtonAbort_clicked();
    void on_treeView_doubleClicked(const QModelIndex& index);
    void on_treeView_expanded(const QModelIndex& index);
    void on_tabButtonLocal_clicked();
    void on_tabButtonMyClasses_clicked();
    void on_tabButtonAllClasses_clicked();
    void on_filterEdit_textEdited();
    void on_filterEdit_textChanged();
    void treeView_selectionChanged(const QModelIndex& current, const QModelIndex&);
    void on_helpNewsButton_clicked();
    void onCenterTimer();
    void iconDownloaded(const QUrl& url, const QIcon& icon);

    void on_leftKey();
    void on_rightKey();
    void on_spaceKey();

  public slots:
    void addSessionsAfterDownload(QNetworkReply* reply);
    void addNewsAfterDownload(QNetworkReply* reply);
    void addHelpAfterDownload(QNetworkReply* reply);
    bool eventFilter(QObject *target, QEvent *event);
};

#endif // DIALOG_H