1 #ifndef _CONSOLE_H_
2 #define _CONSOLE_H_
3 /*
4    Bacula(R) - The Network Backup Solution
5 
6    Copyright (C) 2000-2020 Kern Sibbald
7 
8    The original author of Bacula is Kern Sibbald, with contributions
9    from many others, a complete list can be found in the file AUTHORS.
10 
11    You may use this file and others of this release according to the
12    license defined in the LICENSE file, which includes the Affero General
13    Public License, v3.0 ("AGPLv3") and some additional permissions and
14    terms pursuant to its AGPLv3 Section 7.
15 
16    This notice must be preserved when any source code is
17    conveyed and/or propagated.
18 
19    Bacula(R) is a registered trademark of Kern Sibbald.
20 */
21 /*
22  *   Kern Sibbald, January 2007
23  */
24 
25 #if QT_VERSION >= 0x050000
26 #include <QtWidgets>
27 #else
28 #include <QtGui>
29 #endif
30 #include "pages.h"
31 #include "ui_console.h"
32 #include "bcomm/dircomm.h"
33 
34 #ifndef MAX_NAME_LENGTH
35 #define MAX_NAME_LENGTH 128
36 #endif
37 
38 /*
39  * Structure for obtaining the defaults for a job
40  */
41 struct job_defaults {
42    QString job_name;
43    QString pool_name;
44    QString messages_name;
45    QString client_name;
46    QString store_name;
47    QString where;
48    QString level;
49    QString type;
50    QString fileset_name;
51    QString catalog_name;
52    bool enabled;
53 };
54 
55 //class DIRRES;
56 //class BSOCK;
57 //class JCR;
58 //class CONRES;
59 
60 class Console : public Pages, public Ui::ConsoleForm
61 {
62    Q_OBJECT
63    friend class DirComm;
64 
65 public:
66    Console(QTabWidget *parent);
67    ~Console();
68    int read(int conn);
69    char *msg(int conn);
70    void discardToPrompt(int conn);
71    int write(int conn, const char *msg);
72    int write(int conn, QString msg);
73    int notifyOff(); // enables/disables socket notification - returns the previous state
74    bool notify(int conn, bool enable); // enables/disables socket notification - returns the previous state
75    bool is_notify_enabled(int conn) const;
76    bool getDirComm(int &conn);
77    bool findDirComm(int &conn);
78    void displayToPrompt(int conn);
79    QString returnFromPrompt(int conn);
80 
81    bool dir_cmd(int conn, const char *cmd, QStringList &results);
82    bool dir_cmd(const char *cmd, QStringList &results);
83    bool dir_cmd(QString &cmd, QStringList &results);
84    bool sql_cmd(const char *cmd, QStringList &results);
85    bool sql_cmd(QString &cmd, QStringList &results);
86    bool sql_cmd(int &conn, QString &cmd, QStringList &results);
87    bool sql_cmd(int &conn, const char *cmd, QStringList &results, bool donotify);
88    int write_dir(const char *buf);
89    int write_dir(const char *buf, bool dowait);
90    void write_dir(int conn, const char *buf);
91    void write_dir(int conn, const char *buf, bool dowait);
92    void getDirResName(QString &);
93    void setDirRes(DIRRES *dir);
94    void writeSettings();
95    void readSettings();
96    void setDirectorTreeItem(QTreeWidgetItem *);
97    void terminate();
is_messagesPending()98    bool is_messagesPending() { return m_messages_pending; };
99    bool is_connected();
100    bool is_connected(int conn);
directorTreeItem()101    QTreeWidgetItem *directorTreeItem() { return m_directorTreeItem; };
102    void startTimer();
103    void display_text(const char *buf);
104    void display_text(const QString buf);
105    void display_textf(const char *fmt, ...);
106    void display_html(const QString buf);
107    bool get_job_defaults(struct job_defaults &);
108    bool get_job_defaults(int &conn, struct job_defaults &);
109    const QFont get_font();
110    void beginNewCommand(int conn);
111    void populateLists(bool forcenew);
112 
113 private:
114    bool get_job_defaults(int &conn, struct job_defaults &, bool donotify);
115    void update_cursor(void);
116    void stopTimer();
117    bool is_connectedGui();
118    bool newDirComm(int &conn);
119    void populateLists(int conn);
120 
121 public:
122    QStringList job_list;
123    QStringList restore_list;
124    QStringList client_list;
125    QStringList fileset_list;
126    QStringList messages_list;
127    QStringList pool_list;
128    QStringList storage_list;
129    QStringList type_list;
130    QStringList level_list;
131    QStringList volstatus_list;
132    QStringList mediatype_list;
133    QStringList location_list;
134 
135 public slots:
136    void connect_dir();
137    void status_dir(void);
138    void messages(void);
139    void set_font(void);
140    void poll_messages(void);
141    void consoleHelp();
142    void consoleReload();
143 
144 public:
145    DIRRES *m_dir;                  /* so various pages can reference it */
146    bool m_warningPrevent;
147 
148 private:
149    QTextEdit *m_textEdit;
150    QTextCursor *m_cursor;
151    QTreeWidgetItem *m_directorTreeItem;
152    bool m_messages_pending;
153    QTimer *m_timer;
154    bool messagesPending(bool pend);
155    bool hasFocus();
156    QHash<int, DirComm*> m_dircommHash;
157    int m_dircommCounter;
158 };
159 
160 #endif /* _CONSOLE_H_ */
161