Menu

[r504]: / trunk / src / OptionsDlg.cpp  Maximize  Restore  History

Download this file

304 lines (286 with data), 13.6 kB

  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
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
// CommitMonitor - simple checker for new commits in svn repositories
// Copyright (C) 2007-2010 - Stefan Kueng
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License
// as published by the Free Software Foundation; either version 2
// of the License, or (at your option) any later version.
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software Foundation,
// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
//
#include "StdAfx.h"
#include "Resource.h"
#include "OptionsDlg.h"
#include "PasswordDlg.h"
#include "Registry.h"
#include "AppUtils.h"
#include <string>
#include <Commdlg.h>
using namespace std;
COptionsDlg::COptionsDlg(HWND hParent) : m_pURLInfos(NULL)
{
m_hParent = hParent;
}
COptionsDlg::~COptionsDlg(void)
{
}
LRESULT COptionsDlg::DlgFunc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
UNREFERENCED_PARAMETER(lParam);
switch (uMsg)
{
case WM_INITDIALOG:
{
InitDialog(hwndDlg, IDI_COMMITMONITOR);
AddToolTip(IDC_AUTOSTART, _T("Starts the CommitMonitor automatically when Windows starts up."));
AddToolTip(IDC_TASKBAR_ALWAYSON, _T("If disabled, the taskbar icon is only shown if new commits are available.\nThe CommitMonitor can be shown by 'starting' it again."));
AddToolTip(IDC_DIFFVIEWER, _T("Path to a viewer for unified diff files."));
AddToolTip(IDC_DIFFVIEWERLABEL, _T("Path to a viewer for unified diff files."));
AddToolTip(IDC_ANIMATEICON, _T("Animates the system tray icon as long as there are unread commits"));
AddToolTip(IDC_USETSVN, _T("If TortoiseSVN is installed, use it for showing the differences of commits"));
AddToolTip(IDC_CHECKNEWER, _T("Automatically check for newer versions of CommitMonitor"));
AddToolTip(IDC_NOTIFYCONNECTERROR, _T("When a repository can not be checked due to connection problems,\nchange/animate the icon as if new commits were available."));
AddToolTip(IDC_IGNOREEOL, _T("Ignores end-of-line changes"));
AddToolTip(IDC_IGNORESPACES, _T("Ignores changes in whitespaces in the middle of lines"));
AddToolTip(IDC_IGNOREALLSPACES, _T("Ignores all whitespace changes"));
// initialize the controls
bool bShowTaskbarIcon = !!(DWORD)CRegStdDWORD(_T("Software\\CommitMonitor\\TaskBarIcon"), TRUE);
bool bStartWithWindows = !wstring(CRegStdString(_T("Software\\Microsoft\\Windows\\CurrentVersion\\Run\\CommitMonitor"))).empty();
bool bAnimateIcon = !!CRegStdDWORD(_T("Software\\CommitMonitor\\Animate"), TRUE);
bool bPlaySound = !!CRegStdDWORD(_T("Software\\CommitMonitor\\PlaySound"), TRUE);
bool bUseTSVN = !!CRegStdDWORD(_T("Software\\CommitMonitor\\UseTSVN"), TRUE);
bool bIndicateConnectErrors = !!CRegStdDWORD(_T("Software\\CommitMonitor\\IndicateConnectErrors"), TRUE);
bool bLeftMenu = !!CRegStdDWORD(_T("Software\\CommitMonitor\\LeftClickMenu"), FALSE);
CRegStdString diffViewer = CRegStdString(_T("Software\\CommitMonitor\\DiffViewer"));
CRegStdString notifySound = CRegStdString(_T("Software\\CommitMonitor\\NotificationSound"));
CRegStdDWORD updatecheck = CRegStdDWORD(_T("Software\\CommitMonitor\\CheckNewer"), TRUE);
CRegStdDWORD numlogs = CRegStdDWORD(_T("Software\\CommitMonitor\\NumLogs"), 30);
TCHAR numBuf[30] = {0};
_stprintf_s(numBuf, 30, _T("%ld"), DWORD(numlogs));
SendDlgItemMessage(*this, IDC_TASKBAR_ALWAYSON, BM_SETCHECK, bShowTaskbarIcon ? BST_CHECKED : BST_UNCHECKED, NULL);
SendDlgItemMessage(*this, IDC_AUTOSTART, BM_SETCHECK, bStartWithWindows ? BST_CHECKED : BST_UNCHECKED, NULL);
SendDlgItemMessage(*this, IDC_ANIMATEICON, BM_SETCHECK, bAnimateIcon ? BST_CHECKED : BST_UNCHECKED, NULL);
SendDlgItemMessage(*this, IDC_USETSVN, BM_SETCHECK, bUseTSVN ? BST_CHECKED : BST_UNCHECKED, NULL);
SetDlgItemText(*this, IDC_DIFFVIEWER, wstring(diffViewer).c_str());
SetDlgItemText(*this, IDC_NOTIFICATIONSOUNDPATH, wstring(notifySound).c_str());
SendDlgItemMessage(*this, IDC_NOTIFICATIONSOUND, BM_SETCHECK, bPlaySound ? BST_CHECKED : BST_UNCHECKED, NULL);
SendDlgItemMessage(*this, IDC_CHECKNEWER, BM_SETCHECK, DWORD(updatecheck) ? BST_CHECKED : BST_UNCHECKED, NULL);
SendDlgItemMessage(*this, IDC_NOTIFYCONNECTERROR, BM_SETCHECK, bIndicateConnectErrors ? BST_CHECKED : BST_UNCHECKED, NULL);
SendDlgItemMessage(*this, IDC_LEFTMENU, BM_SETCHECK, bLeftMenu ? BST_CHECKED : BST_UNCHECKED, NULL);
wstring tsvninstalled = CAppUtils::GetTSVNPath();
wstring sVer = CAppUtils::GetVersionStringFromExe(tsvninstalled.c_str());
if (tsvninstalled.empty() || (_tstoi(sVer.substr(3, 4).c_str()) < 5))
DialogEnableWindow(IDC_USETSVN, FALSE);
SetDlgItemText(*this, IDC_NUMLOGS, numBuf);
CRegStdString diffParams = CRegStdString(_T("Software\\CommitMonitor\\DiffParameters"));
bool ignoreeol = wstring(diffParams).find(_T("--ignore-eol-style")) != wstring::npos;
bool ignorewhitespaces = wstring(diffParams).find(_T("-b")) != wstring::npos;
bool ignoreallwhitespaces = wstring(diffParams).find(_T("-w")) != wstring::npos;
SendDlgItemMessage(*this, IDC_IGNOREEOL, BM_SETCHECK, ignoreeol ? BST_CHECKED : BST_UNCHECKED, NULL);
SendDlgItemMessage(*this, IDC_IGNORESPACES, BM_SETCHECK, ignorewhitespaces ? BST_CHECKED : BST_UNCHECKED, NULL);
SendDlgItemMessage(*this, IDC_IGNOREALLSPACES, BM_SETCHECK, ignoreallwhitespaces ? BST_CHECKED : BST_UNCHECKED, NULL);
ExtendFrameIntoClientArea(0, 0, 0, IDC_AEROLABEL);
m_aerocontrols.SubclassControl(GetDlgItem(*this, IDOK));
m_aerocontrols.SubclassControl(GetDlgItem(*this, IDCANCEL));
}
return TRUE;
case WM_COMMAND:
return DoCommand(LOWORD(wParam));
default:
return FALSE;
}
}
LRESULT COptionsDlg::DoCommand(int id)
{
switch (id)
{
case IDOK:
{
CRegStdDWORD regShowTaskbarIcon = CRegStdDWORD(_T("Software\\CommitMonitor\\TaskBarIcon"), TRUE);
CRegStdString regStartWithWindows = CRegStdString(_T("Software\\Microsoft\\Windows\\CurrentVersion\\Run\\CommitMonitor"));
CRegStdDWORD regAnimateIcon = CRegStdDWORD(_T("Software\\CommitMonitor\\Animate"), TRUE);
CRegStdDWORD regPlaySound = CRegStdDWORD(_T("Software\\CommitMonitor\\PlaySound"), TRUE);
CRegStdDWORD regUseTSVN = CRegStdDWORD(_T("Software\\CommitMonitor\\UseTSVN"), TRUE);
CRegStdDWORD updatecheck = CRegStdDWORD(_T("Software\\CommitMonitor\\CheckNewer"), TRUE);
CRegStdDWORD numlogs = CRegStdDWORD(_T("Software\\CommitMonitor\\NumLogs"), 30);
CRegStdDWORD regIndicateErrors = CRegStdDWORD(_T("Software\\CommitMonitor\\IndicateConnectErrors"), TRUE);
CRegStdDWORD regLeftMenu = CRegStdDWORD(_T("Software\\CommitMonitor\\LeftClickMenu"), FALSE);
bool bShowTaskbarIcon = !!SendDlgItemMessage(*this, IDC_TASKBAR_ALWAYSON, BM_GETCHECK, 0, NULL);
bool bStartWithWindows = !!SendDlgItemMessage(*this, IDC_AUTOSTART, BM_GETCHECK, 0, NULL);
bool bAnimateIcon = !!SendDlgItemMessage(*this, IDC_ANIMATEICON, BM_GETCHECK, 0, NULL);
bool bPlaySound = !!SendDlgItemMessage(*this, IDC_NOTIFICATIONSOUND, BM_GETCHECK, 0, NULL);
bool bUseTSVN = !!SendDlgItemMessage(*this, IDC_USETSVN, BM_GETCHECK, 0, NULL);
bool bUpdateCheck = !!SendDlgItemMessage(*this, IDC_CHECKNEWER, BM_GETCHECK, 0, NULL);
bool bIndicateConnectErrors = !!SendDlgItemMessage(*this, IDC_NOTIFYCONNECTERROR, BM_GETCHECK, 0, NULL);
bool bLeftMenu = !!SendDlgItemMessage(*this, IDC_LEFTMENU, BM_GETCHECK, 0, NULL);
regShowTaskbarIcon = bShowTaskbarIcon;
regAnimateIcon = bAnimateIcon;
regPlaySound = bPlaySound;
regUseTSVN = bUseTSVN;
updatecheck = bUpdateCheck;
regIndicateErrors = bIndicateConnectErrors;
regLeftMenu = bLeftMenu;
::SendMessage(m_hHiddenWnd, COMMITMONITOR_CHANGEDINFO, 0, 0);
if (bStartWithWindows)
{
TCHAR buf[MAX_PATH*4];
GetModuleFileName(NULL, buf, MAX_PATH*4);
wstring cmd = wstring(buf);
cmd += _T(" /hidden");
regStartWithWindows = cmd;
}
else
regStartWithWindows.removeValue();
int len = ::GetWindowTextLength(GetDlgItem(*this, IDC_DIFFVIEWER));
TCHAR * divi = new TCHAR[len+1];
::GetDlgItemText(*this, IDC_DIFFVIEWER, divi, len+1);
wstring dv = wstring(divi);
delete [] divi;
CRegStdString diffViewer = CRegStdString(_T("Software\\CommitMonitor\\DiffViewer"));
if (!dv.empty())
diffViewer = dv;
else
diffViewer.removeValue();
len = ::GetWindowTextLength(GetDlgItem(*this, IDC_NOTIFICATIONSOUNDPATH));
divi = new TCHAR[len+1];
::GetDlgItemText(*this, IDC_NOTIFICATIONSOUNDPATH, divi, len+1);
wstring ns = wstring(divi);
delete [] divi;
CRegStdString notifySound = CRegStdString(_T("Software\\CommitMonitor\\NotificationSound"));
if (!ns.empty())
notifySound = ns;
else
notifySound.removeValue();
len = ::GetWindowTextLength(GetDlgItem(*this, IDC_NUMLOGS));
divi = new TCHAR[len+1];
::GetDlgItemText(*this, IDC_NUMLOGS, divi, len+1);
DWORD nLogs = _ttol(divi);
numlogs = nLogs;
delete [] divi;
CRegStdString diffParams = CRegStdString(_T("Software\\CommitMonitor\\DiffParameters"));
bool ignoreeol = !!SendDlgItemMessage(*this, IDC_IGNOREEOL, BM_GETCHECK, 0, NULL);
bool ignorewhitespaces = !!SendDlgItemMessage(*this, IDC_IGNORESPACES, BM_GETCHECK, 0, NULL);
bool ignoreallwhitespaces = !!SendDlgItemMessage(*this, IDC_IGNOREALLSPACES, BM_GETCHECK, 0, NULL);
diffParams = SVN::GetOptionsString(ignoreeol, ignorewhitespaces, ignoreallwhitespaces);
}
// fall through
case IDCANCEL:
EndDialog(*this, id);
break;
case IDC_IGNOREALLSPACES:
{
bool ignoreallwhitespaces = !!SendDlgItemMessage(*this, IDC_IGNOREALLSPACES, BM_GETCHECK, 0, NULL);
if (ignoreallwhitespaces)
SendDlgItemMessage(*this, IDC_IGNORESPACES, BM_SETCHECK, BST_UNCHECKED, NULL);
}
break;
case IDC_IGNORESPACES:
{
bool ignorewhitespaces = !!SendDlgItemMessage(*this, IDC_IGNORESPACES, BM_GETCHECK, 0, NULL);
if (ignorewhitespaces)
SendDlgItemMessage(*this, IDC_IGNOREALLSPACES, BM_SETCHECK, BST_UNCHECKED, NULL);
}
break;
case IDC_EXPORT:
{
if (m_pURLInfos)
{
CPasswordDlg dlg(*this);
if (dlg.DoModal(hResource, IDD_PASSWORD, *this) == IDOK)
{
OPENFILENAME ofn = {0}; // common dialog box structure
TCHAR szFile[MAX_PATH] = {0}; // buffer for file name
// Initialize OPENFILENAME
ofn.lStructSize = sizeof(OPENFILENAME);
ofn.hwndOwner = *this;
ofn.lpstrFile = szFile;
ofn.nMaxFile = sizeof(szFile)/sizeof(TCHAR);
ofn.lpstrTitle = _T("Export monitored projects to...\0");
ofn.Flags = OFN_HIDEREADONLY|OFN_DONTADDTORECENT|OFN_EXPLORER|OFN_ENABLESIZING|OFN_OVERWRITEPROMPT;
ofn.lpstrFilter = _T("CommitMonitor Projects\0*.cmprj;*.com\0All files\0*.*\0\0");
ofn.nFilterIndex = 1;
// Display the Open dialog box.
if (GetSaveFileName(&ofn)==TRUE)
{
if (wcscmp(&szFile[wcslen(szFile)-6], L".cmprj"))
wcscat_s(szFile, MAX_PATH, L".cmprj");
m_pURLInfos->Export(szFile, dlg.password.c_str());
}
}
}
}
break;
case IDC_IMPORT:
{
if (m_pURLInfos)
{
CPasswordDlg dlg(*this);
if (dlg.DoModal(hResource, IDD_PASSWORD, *this) == IDOK)
{
OPENFILENAME ofn = {0}; // common dialog box structure
TCHAR szFile[MAX_PATH] = {0}; // buffer for file name
// Initialize OPENFILENAME
ofn.lStructSize = sizeof(OPENFILENAME);
ofn.hwndOwner = *this;
ofn.lpstrFile = szFile;
ofn.nMaxFile = sizeof(szFile)/sizeof(TCHAR);
ofn.lpstrTitle = _T("Import monitored projects from...\0");
ofn.Flags = OFN_FILEMUSTEXIST|OFN_HIDEREADONLY|OFN_PATHMUSTEXIST|OFN_DONTADDTORECENT;
ofn.lpstrFilter = _T("CommitMonitor Projects\0*.cmprj;*.com\0All files\0*.*\0\0");
ofn.nFilterIndex = 1;
// Display the Open dialog box.
if (GetOpenFileName(&ofn)==TRUE)
{
m_pURLInfos->Import(szFile, dlg.password.c_str());
}
}
}
}
break;
case IDC_DIFFBROWSE:
{
OPENFILENAME ofn = {0}; // common dialog box structure
TCHAR szFile[MAX_PATH] = {0}; // buffer for file name
// Initialize OPENFILENAME
ofn.lStructSize = sizeof(OPENFILENAME);
ofn.hwndOwner = *this;
ofn.lpstrFile = szFile;
ofn.nMaxFile = sizeof(szFile)/sizeof(TCHAR);
ofn.lpstrTitle = _T("Select Diff Viewer...\0");
ofn.Flags = OFN_FILEMUSTEXIST|OFN_HIDEREADONLY|OFN_PATHMUSTEXIST|OFN_DONTADDTORECENT;
ofn.lpstrFilter = _T("Programs\0*.exe;*.com\0All files\0*.*\0\0");
ofn.nFilterIndex = 1;
// Display the Open dialog box.
if (GetOpenFileName(&ofn)==TRUE)
{
SetDlgItemText(*this, IDC_DIFFVIEWER, szFile);
}
}
break;
case IDC_SOUNDBROWSE:
{
OPENFILENAME ofn = {0}; // common dialog box structure
TCHAR szFile[MAX_PATH] = {0}; // buffer for file name
// Initialize OPENFILENAME
ofn.lStructSize = sizeof(OPENFILENAME);
ofn.hwndOwner = *this;
ofn.lpstrFile = szFile;
ofn.nMaxFile = sizeof(szFile)/sizeof(TCHAR);
ofn.lpstrTitle = _T("Select Notification Sound...\0");
ofn.Flags = OFN_FILEMUSTEXIST|OFN_HIDEREADONLY|OFN_PATHMUSTEXIST|OFN_DONTADDTORECENT;
ofn.lpstrFilter = _T("Sound Files\0*.wav;*.mp3\0All files\0*.*\0\0");
ofn.nFilterIndex = 1;
// Display the Open dialog box.
if (GetOpenFileName(&ofn)==TRUE)
{
SetDlgItemText(*this, IDC_NOTIFICATIONSOUNDPATH, szFile);
}
}
break;
}
return 1;
}
Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.