Debian Codegraph @

DatabaseExplorer/db_explorer_settings.h

raw
1 //////////////////////////////////////////////////////////////////////////////
2 //////////////////////////////////////////////////////////////////////////////
3 //
4 // copyright : (C) 2014 Eran Ifrah
5 // file name : db_explorer_settings.h
6 //
7 // -------------------------------------------------------------------------
8 // A
9 // _____ _ _ _ _
10 // / __ \ | | | | (_) |
11 // | / \/ ___ __| | ___| | _| |_ ___
12 // | | / _ \ / _ |/ _ \ | | | __/ _ )
13 // | \__/\ (_) | (_| | __/ |___| | || __/
14 // \____/\___/ \__,_|\___\_____/_|\__\___|
15 //
16 // F i l e
17 //
18 // This program is free software; you can redistribute it and/or modify
19 // it under the terms of the GNU General Public License as published by
20 // the Free Software Foundation; either version 2 of the License, or
21 // (at your option) any later version.
22 //
23 //////////////////////////////////////////////////////////////////////////////
24 //////////////////////////////////////////////////////////////////////////////
25
26 #ifndef DBEXPLORERSETTINGS_H
27 #define DBEXPLORERSETTINGS_H
28
29 #include "serialized_object.h"
30 #include "cl_config.h"
31
32 #define DBE_CONFIG "database-explorer"
33 #define DBE_CONFIG_FILE "database-explorer.conf"
34
35 class DbConnectionInfo : public clConfigItem
36 {
37 protected:
38 wxString m_connectionName;
39 wxString m_server;
40 int m_port;
41 wxString m_password;
42 wxString m_username;
43 wxString m_defaultDatabase;
44 int m_connectionType;
45
46 public:
47 enum {
48 DbConnTypeMySQL,
49 DbConnTypePgSQL
50 };
51
52 public:
53 DbConnectionInfo();
54 virtual ~DbConnectionInfo();
55
56 virtual void FromJSON(const JSONItem& json);
57 virtual JSONItem ToJSON() const;
58
59 void SetConnectionName(const wxString& connectionName) {
60 this->m_connectionName = connectionName;
61 }
62 void SetPassword(const wxString& password) {
63 this->m_password = password;
64 }
65 void SetServer(const wxString& server) {
66 this->m_server = server;
67 }
68 void SetPort(const int port) {
69 this->m_port = port;
70 }
71 void SetUsername(const wxString& username) {
72 this->m_username = username;
73 }
74 const wxString& GetConnectionName() const {
75 return m_connectionName;
76 }
77 const wxString& GetPassword() const {
78 return m_password;
79 }
80 const wxString& GetServer() const {
81 return m_server;
82 }
83 const int GetPort() const {
84 return m_port;
85 }
86 const wxString& GetUsername() const {
87 return m_username;
88 }
89 void SetDefaultDatabase(const wxString& defaultDatabase) {
90 this->m_defaultDatabase = defaultDatabase;
91 }
92 const wxString& GetDefaultDatabase() const {
93 return m_defaultDatabase;
94 }
95 void SetConnectionType(int connectionType) {
96 this->m_connectionType = connectionType;
97 }
98 int GetConnectionType() const {
99 return m_connectionType;
100 }
101
102 bool IsValid() const {
103 return !m_connectionName.IsEmpty() &&
104 !m_server.IsEmpty() &&
105 !m_username.IsEmpty() &&
106 !m_password.IsEmpty();
107 }
108 };
109
110 typedef std::vector<DbConnectionInfo> DbConnectionInfoVec;
111
112 class DbExplorerSettings : public clConfigItem
113 {
114 protected:
115 wxArrayString m_recentFiles;
116 DbConnectionInfoVec m_connections;
117 wxArrayString m_sqlHistory;
118
119 public:
120 DbExplorerSettings();
121 virtual ~DbExplorerSettings();
122
123 void SetRecentFiles(const wxArrayString& recentFiles);
124 const wxArrayString& GetRecentFiles() const {
125 return m_recentFiles;
126 }
127
128 DbConnectionInfoVec GetPgSQLConnections();
129 void SetPgSQLConnections(const DbConnectionInfoVec& conns);
130
131 DbConnectionInfoVec GetMySQLConnections();
132 void SetMySQLConnections(const DbConnectionInfoVec& conns);
133
134 void SetSqlHistory(const wxArrayString& sqlHistory) {
135 this->m_sqlHistory = sqlHistory;
136 }
137 const wxArrayString& GetSqlHistory() const {
138 return m_sqlHistory;
139 }
140 virtual void FromJSON(const JSONItem &json);
141 virtual JSONItem ToJSON() const;
142 };
143
144 #endif // DBEXPLORERSETTINGS_H