File: misc.h

package info (click to toggle)
pgadmin3 1.20.0~beta2-1
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 73,704 kB
  • ctags: 18,591
  • sloc: cpp: 193,786; ansic: 18,736; sh: 5,154; pascal: 1,120; yacc: 927; makefile: 516; lex: 421; xml: 126; perl: 40
file content (273 lines) | stat: -rw-r--r-- 7,936 bytes parent folder | download
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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
//////////////////////////////////////////////////////////////////////////
//
// pgAdmin III - PostgreSQL Tools
//
// Copyright (C) 2002 - 2014, The pgAdmin Development Team
// This software is released under the PostgreSQL Licence
//
// misc.h - Miscellaneous Utilties
//
//////////////////////////////////////////////////////////////////////////

#ifndef MISC_H
#define MISC_H

#include <wx/wx.h>
#include <wx/datetime.h>
#include <wx/tokenzr.h>

#include "utils/misc.h"

class wxImageList;
extern wxImageList *imageList;

class wxHelpControllerBase;

#define __(str) wxT(str)

typedef unsigned long OID;
#define SSH_MAX_PASSWORD_LEN 256

// we dont have an appropriate wxLongLong method
#ifdef __WIN32__
#define atolonglong _atoi64
#else
#ifdef __WXMAC__
#define atolonglong(str) strtoll(str, (char **)NULL, 10)
#else
#ifdef __FreeBSD__
#define atolonglong(str) strtoll(str, (char **)NULL, 10)
#else
#define atolonglong atoll
#endif
#endif
#endif

#ifdef __WXMSW__
#define END_OF_LINE wxT("\r\n")
#else
#define END_OF_LINE wxT("\n")
#endif

#if !defined(PGSCLI)

#define wxCookieType wxTreeItemIdValue

class sysSettings;
extern sysSettings *settings;

#undef wxStaticCast
#define wxStaticCast(obj, className) ((className *)(obj))

// making life easier
#define CTRL(id, typ)           (XRCCTRL(*this, id, typ))

#define CTRL_STATIC(id)         (XRCCTRL(*this, id, wxStaticText))
#define CTRL_STATICBOX(id)      (XRCCTRL(*this, id, wxStaticBox))
#define CTRL_TEXT(id)           (XRCCTRL(*this, id, wxTextCtrl))
#define CTRL_TEXTNUMERIC(id)    ((wxTextNumericCtrl*)(XRCCTRL(*this, id, wxTextCtrl)))
#define CTRL_LISTBOX(id)        (XRCCTRL(*this, id, wxListBox))
#define CTRL_LISTCTRL(id)       (XRCCTRL(*this, id, wxListCtrl))
#define CTRL_COMBOBOX(id)       ((ctlComboBoxFix*)(XRCCTRL(*this, id, wxComboBox)))
#define CTRL_COMBOBOX1(id)      (XRCCTRL(*this, id, wxComboBox))
#define CTRL_LISTVIEW(id)       ((ctlListView*)(XRCCTRL(*this, id, wxListCtrl)))
#define CTRL_COMBOBOX2(id)      (XRCCTRL(*this, id, ctlComboBox))
#define CTRL_CHOICE(id)         (XRCCTRL(*this, id, wxChoice))
#define CTRL_CHECKBOX(id)       (XRCCTRL(*this, id, wxCheckBox))
#define CTRL_RADIOBOX(id)       (XRCCTRL(*this, id, wxRadioBox))
#define CTRL_BUTTON(id)         (XRCCTRL(*this, id, wxButton))
#define CTRL_CALENDAR(id)       (XRCCTRL(*this, id, wxCalendarBox))
#define CTRL_TIME(id)           (XRCCTRL(*this, id, wxTimeSpinCtrl))
#define CTRL_FLEXGRIDSIZER(id)  (XRCCTRL(*this, id, wxFlexGridSizer))
#define CTRL_PANEL(id)          (XRCCTRL(*this, id, wxPanel))
#define CTRL_SLIDER(id)         (XRCCTRL(*this, id, wxSlider))
#define CTRL_SQLBOX(id)         (XRCCTRL(*this, id, ctlSQLBox))
#define CTRL_RADIOBUTTON(id)    (XRCCTRL(*this, id, wxRadioButton))
#define CTRL_NOTEBOOK(id)       (XRCCTRL(*this, id, wxNotebook))
#define CTRL_SPIN(id)           (XRCCTRL(*this, id, wxSpinCtrl))
#define CTRL_CHECKLISTBOX(id)   (XRCCTRL(*this, id, wxCheckListBox))
#define CTRL_DATEPICK(id)       (XRCCTRL(*this, id, wxDatePickerCtrl))
#define CTRL_TREE(id)           (XRCCTRL(*this, id, ctlTree))
#define CTRL_COLOURPICKER(id)   (XRCCTRL(*this, id, ctlColourPicker))
#define CTRL_DIRPICKER(id)      (XRCCTRL(*this, id, wxDirPickerCtrl))
#define CTRL_FILEPICKER(id)     (XRCCTRL(*this, id, wxFilePickerCtrl))
#define CTRL_FONTPICKER(id)     (XRCCTRL(*this, id, wxFontPickerCtrl))
#define CTRL_CHECKTREEVIEW(id)  (XRCCTRL(*this, id, ctlCheckTreeView))
#define CTRL_GAUGE(id)          (XRCCTRL(*this, id, wxGauge))

#endif // PGSCLI

// Conversions
wxString BoolToStr(bool value);         // english; used for config values
wxString DateToAnsiStr(const wxDateTime &datetime);

bool StrToBool(const wxString &value);  // english
long StrToLong(const wxString &value);
double StrToDouble(const wxString &value);
wxLongLong StrToLongLong(const wxString &value);
wxDateTime StrToDateTime(const wxString &value);
OID StrToOid(const wxString &value);

wxString generate_spaces(int length);

// nls aware
wxString BoolToYesNo(bool value);
wxString NumToStr(long value);
wxString NumToStr(double value);
wxString NumToStr(OID value);
wxString NumToStr(wxLongLong value);
wxString DateToStr(const wxDateTime &datetime);


// Quoting
wxString qtConnString(const wxString &value); // connection strings always have single quotes escaped with backslash

#if !defined(PGSCLI)

// check if size/pos have reasonable values
void CheckOnScreen(wxWindow *win, wxPoint &pos, wxSize &size, const int w0 = 100, const int h0 = 70);

// compile ID and Name into one string
wxString IdAndName(long id, const wxString &name);

// Quoting
wxString qtDbStringDollar(const wxString &value);
wxString qtStrip(const wxString &value);    // remove \"


// string build helper
void AppendIfFilled(wxString &str, const wxString &delimiter, const wxString &what);

// Create keyword list from PostgreSQL list
void FillKeywords(wxString &str);

// Recreate a 9.0 datconfig
wxString TransformToNewDatconfig(const wxString &list);

// Fill array, splitting the string separated by commas (maybe quoted elements)
void FillArray(wxArrayString &array, const wxString &str);


// splitting of strings, obeying quotes
class queryTokenizer : public wxStringTokenizer
{
public:
	queryTokenizer(const wxString &str, const wxChar delim = (wxChar)' ');
	wxString GetNextToken();
private:
	char delimiter;
};

// Get an array from a comma(,) separated list
bool getArrayFromCommaSeparatedList(const wxString &str, wxArrayString &res);

// File handling including encoding according to sysSettings if format<0,
// 0-> local charset, 1->utf8
wxString FileRead(const wxString &filename, int format = -1);
bool FileWrite(const wxString &filename, const wxString &data, int format = -1);

typedef enum
{
    HELP_PGADMIN,
    HELP_POSTGRESQL,
    HELP_ENTERPRISEDB,
    HELP_GREENPLUM,
    HELP_SLONY
} HelpType;

wxString CleanHelpPath(const wxString &path);
bool HelpPathValid(const wxString &path);
void DisplayHelp(const wxString &helpTopic, const HelpType helpType);
void DisplayPgAdminHelp(const wxString &helpTopic);
void DisplayExternalHelp(const wxString &helpTopic, const wxString &docPath, wxHelpControllerBase *helpCtl, const bool init);

#ifndef WIN32
wxString ExecProcess(const wxString &cmd);
int ExecProcess(const wxString &command, wxArrayString &result);
#endif

wxString GetHtmlEntity(const wxChar ch);
wxString HtmlEntities(const wxString &str);

wxString firstLineOnly(const wxString &str);

bool pgAppMinimumVersion(const wxString &cmd, const int majorVer, const int minorVer);
bool isPgApp(const wxString &app);
bool isEdbApp(const wxString &app);
bool isGpApp(const wxString &app);

enum
{
    EDB_PACKAGE,
    EDB_PACKAGEFUNCTION,
    EDB_PACKAGEVARIABLE,
    EDB_SYNONYM,

    PGM_CATALOG,
    PGM_CATALOGOBJECT,
    PGM_CHECK,
    PGM_COLUMN,
    PGM_CONSTRAINT,
    PGM_DATABASE,
    PGM_DOMAIN,
    PGM_EXCLUDE,
    PGM_FOREIGNKEY,
    PGM_FOREIGNSERVER,
    PGM_FOREIGNTABLE,
    PGM_USERMAPPING,
    PGM_FUNCTION,
    PGM_INDEX,
    PGM_OPCLASS,
    PGM_OPFAMILY,
    PGM_PRIMARYKEY,
    PGM_ROLE,
    PGM_RULE,
    PGM_SCHEMA,
    PGM_SERVER,
    PGM_SEQUENCE,
    PGM_TABLE,
    PGM_TABLESPACE,
    PGM_TRIGGER,
    PGM_UNKNOWN,
    PGM_UNIQUE,
    PGM_VIEW,

    GP_EXTTABLE,
    GP_RESOURCE_QUEUE,
    GP_PARTITION,

    PGM_JOB,
    PGM_SCHEDULE,
    PGM_STEP,

    SLM_LISTEN,
    SLM_NODE,
    SLM_PATH,
    SLM_SEQUENCE,
    SLM_SET,
    SLM_SUBSCRIPTION,
    SLM_TABLE,

    PGM_LANGUAGE,
    PGM_EVENTTRIGGER
};


enum        // depends on pgaFactory::addImage order!
{
    PGICON_PROPERTY,
    PGICON_STATISTICS,
    PGICON_PUBLIC
};

// File/directory name cleanup
wxString sanitizePath(const wxString &path);
wxString commandLineCleanOption(const wxString &option, bool schemaObject = false);
#endif // PGSCLI

// Quoting
wxString qtIdent(const wxString &value);    // add " if necessary
wxString qtTypeIdent(const wxString &value);    // add " if necessary

#endif