OSDN Git Service

merge original branch.
[tortoisegit/TortoiseGitJp.git] / src / TortoiseProc / Settings / Settings.cpp
1 // TortoiseSVN - a Windows shell extension for easy version control\r
2 \r
3 // Copyright (C) 2003-2008 - TortoiseSVN\r
4 \r
5 // This program is free software; you can redistribute it and/or\r
6 // modify it under the terms of the GNU General Public License\r
7 // as published by the Free Software Foundation; either version 2\r
8 // of the License, or (at your option) any later version.\r
9 \r
10 // This program is distributed in the hope that it will be useful,\r
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of\r
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\r
13 // GNU General Public License for more details.\r
14 \r
15 // You should have received a copy of the GNU General Public License\r
16 // along with this program; if not, write to the Free Software Foundation,\r
17 // 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.\r
18 //\r
19 #include "stdafx.h"\r
20 #include "TortoiseProc.h"\r
21 #include "Settings.h"\r
22 #include "MessageBox.h"\r
23 #include "..\..\TGitCache\CacheInterface.h"\r
24 #include "CommonResource.h"\r
25 #include "GitAdminDir.h"\r
26 \r
27 IMPLEMENT_DYNAMIC(CSettings, CTreePropSheet)\r
28 CSettings::CSettings(UINT nIDCaption,CTGitPath *cmdPath, CWnd* pParentWnd, UINT iSelectPage)\r
29         :CTreePropSheet(nIDCaption, pParentWnd, iSelectPage)\r
30 {\r
31         if(cmdPath)\r
32                 this->m_CmdPath=*cmdPath;\r
33 \r
34         m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);\r
35         AddPropPages();\r
36 }\r
37 \r
38 CSettings::~CSettings()\r
39 {\r
40         RemovePropPages();\r
41 }\r
42 \r
43 void CSettings::AddPropPages()\r
44 {\r
45         m_pMainPage = new CSetMainPage();\r
46         m_pOverlayPage = new CSetOverlayPage();\r
47         m_pOverlaysPage = new CSetOverlayIcons();\r
48         m_pProxyPage = new CSetProxyPage();\r
49         m_pProgsDiffPage = new CSettingsProgsDiff();\r
50         m_pProgsMergePage = new CSettingsProgsMerge();\r
51         m_pProgsUniDiffPage = new CSettingsProgsUniDiff();\r
52         m_pLookAndFeelPage = new CSetLookAndFeelPage();\r
53         \r
54         m_pExtMenu      = new CSetExtMenu();\r
55 \r
56         m_pDialogsPage = new CSetDialogs();\r
57         m_pMiscPage = new CSetMisc();\r
58         m_pRevisionGraphPage = new CSettingsRevisionGraph();\r
59 //      m_pLogCachePage = new CSetLogCache();\r
60 //      m_pLogCacheListPage = new CSettingsLogCaches();\r
61         m_pColorsPage = new CSettingsColors();\r
62     m_pColorsPage2 = new CSettingsColors2();\r
63     m_pColorsPage3 = new CSettingsColors3();\r
64         m_pSavedPage = new CSetSavedDataPage();\r
65 //      m_pHooksPage = new CSetHooks();\r
66         m_pBugTraqPage = new CSetBugTraq();\r
67         m_pTBlamePage = new CSettingsTBlame();\r
68         m_pGitConfig = new CSettingGitConfig();\r
69         m_pGitRemote = new CSettingGitRemote(m_CmdPath.GetWinPath());\r
70         m_pBugtraqConfig = new CSettingsBugtraqConfig(m_CmdPath.GetWinPath());\r
71 \r
72 \r
73         SetPageIcon(m_pExtMenu,m_pExtMenu->GetIconID());\r
74 \r
75         SetPageIcon(m_pMainPage, m_pMainPage->GetIconID());\r
76         SetPageIcon(m_pOverlayPage, m_pOverlayPage->GetIconID());\r
77         SetPageIcon(m_pOverlaysPage, m_pOverlaysPage->GetIconID());\r
78         SetPageIcon(m_pProxyPage, m_pProxyPage->GetIconID());\r
79         SetPageIcon(m_pProgsDiffPage, m_pProgsDiffPage->GetIconID());\r
80         SetPageIcon(m_pProgsMergePage, m_pProgsMergePage->GetIconID());\r
81         SetPageIcon(m_pProgsUniDiffPage, m_pProgsUniDiffPage->GetIconID());\r
82         SetPageIcon(m_pLookAndFeelPage, m_pLookAndFeelPage->GetIconID());\r
83         SetPageIcon(m_pDialogsPage, m_pDialogsPage->GetIconID());\r
84         SetPageIcon(m_pRevisionGraphPage, m_pRevisionGraphPage->GetIconID());\r
85         SetPageIcon(m_pMiscPage, m_pMiscPage->GetIconID());\r
86 ////    SetPageIcon(m_pLogCachePage, m_pLogCachePage->GetIconID());\r
87 //      SetPageIcon(m_pLogCacheListPage, m_pLogCacheListPage->GetIconID());\r
88         SetPageIcon(m_pColorsPage, m_pColorsPage->GetIconID());\r
89     SetPageIcon(m_pColorsPage2, m_pColorsPage2->GetIconID());\r
90     SetPageIcon(m_pColorsPage3, m_pColorsPage3->GetIconID());\r
91 \r
92         SetPageIcon(m_pSavedPage, m_pSavedPage->GetIconID());\r
93 //      SetPageIcon(m_pHooksPage, m_pHooksPage->GetIconID());\r
94 \r
95         SetPageIcon(m_pGitConfig, m_pGitConfig->GetIconID());\r
96         SetPageIcon(m_pGitRemote, m_pGitRemote->GetIconID());\r
97         SetPageIcon(m_pBugTraqPage, m_pBugTraqPage->GetIconID());\r
98         SetPageIcon(m_pBugtraqConfig, m_pBugtraqConfig->GetIconID());\r
99         SetPageIcon(m_pTBlamePage, m_pTBlamePage->GetIconID());\r
100 \r
101         AddPage(m_pMainPage);\r
102         AddPage(m_pOverlayPage);\r
103         AddPage(m_pOverlaysPage);\r
104         AddPage(m_pProxyPage);\r
105         AddPage(m_pProgsDiffPage);\r
106         AddPage(m_pProgsMergePage);\r
107         AddPage(m_pProgsUniDiffPage);\r
108         AddPage(m_pLookAndFeelPage);\r
109         AddPage(m_pExtMenu);\r
110         AddPage(m_pDialogsPage);\r
111         AddPage(m_pMiscPage);\r
112         AddPage(m_pRevisionGraphPage);\r
113         AddPage(m_pColorsPage);\r
114         AddPage(m_pColorsPage2);\r
115         AddPage(m_pColorsPage3);\r
116         AddPage(m_pSavedPage);\r
117 \r
118         AddPage(m_pGitConfig);\r
119 \r
120         if(     g_GitAdminDir.HasAdminDir(this->m_CmdPath.GetWinPath()) )\r
121         {\r
122                 AddPage(m_pGitRemote);\r
123         }\r
124 //      AddPage(m_pGitRemotem_pLogCachePage);\r
125 //    AddPage(m_pLogCacheListPage);\r
126 //      AddPage(m_pHooksPage);\r
127         AddPage(m_pBugTraqPage);\r
128         if(     g_GitAdminDir.HasAdminDir(this->m_CmdPath.GetWinPath()) )\r
129         {\r
130                 AddPage(m_pBugtraqConfig);\r
131         }\r
132         AddPage(m_pTBlamePage);\r
133 }\r
134 \r
135 void CSettings::RemovePropPages()\r
136 {\r
137         delete m_pMainPage;\r
138         delete m_pOverlayPage;\r
139         delete m_pOverlaysPage;\r
140         delete m_pProxyPage;\r
141         delete m_pProgsDiffPage;\r
142         delete m_pProgsMergePage;\r
143         delete m_pProgsUniDiffPage;\r
144         delete m_pLookAndFeelPage;\r
145         delete m_pDialogsPage;\r
146     delete m_pRevisionGraphPage;\r
147         delete m_pMiscPage;\r
148 ////    delete m_pLogCachePage;\r
149 ////    delete m_pLogCacheListPage;\r
150         delete m_pColorsPage;\r
151         delete m_pColorsPage2;\r
152         delete m_pColorsPage3;\r
153         delete m_pSavedPage;\r
154 //      delete m_pHooksPage;\r
155         delete m_pBugTraqPage;\r
156         delete m_pTBlamePage;\r
157 \r
158         delete m_pGitConfig;\r
159         delete m_pGitRemote;\r
160         delete m_pBugtraqConfig;\r
161         delete m_pExtMenu;\r
162 \r
163 }\r
164 \r
165 void CSettings::HandleRestart()\r
166 {\r
167         int restart = ISettingsPropPage::Restart_None;\r
168         restart |= m_pMainPage->GetRestart();\r
169         restart |= m_pOverlayPage->GetRestart();\r
170         restart |= m_pOverlaysPage->GetRestart();\r
171         restart |= m_pProxyPage->GetRestart();\r
172         restart |= m_pProgsDiffPage->GetRestart();\r
173         restart |= m_pProgsMergePage->GetRestart();\r
174         restart |= m_pProgsUniDiffPage->GetRestart();\r
175         restart |= m_pLookAndFeelPage->GetRestart();\r
176         restart |= m_pDialogsPage->GetRestart();\r
177     restart |= m_pRevisionGraphPage->GetRestart();\r
178         restart |= m_pMiscPage->GetRestart();\r
179 ////    restart |= m_pLogCachePage->GetRestart();\r
180 //      restart |= m_pLogCacheListPage->GetRestart();\r
181         restart |= m_pColorsPage->GetRestart();\r
182         restart |= m_pColorsPage2->GetRestart();\r
183         restart |= m_pColorsPage3->GetRestart();\r
184         restart |= m_pSavedPage->GetRestart();\r
185 ////    restart |= m_pHooksPage->GetRestart();\r
186         restart |= m_pBugTraqPage->GetRestart();\r
187         restart |= m_pTBlamePage->GetRestart();\r
188 \r
189         restart |= m_pGitConfig->GetRestart();\r
190         restart |= m_pGitRemote->GetRestart();\r
191         restart |= m_pBugTraqPage->GetRestart();\r
192         restart |= m_pExtMenu->GetRestart();\r
193 \r
194         if (restart & ISettingsPropPage::Restart_System)\r
195         {\r
196                 DWORD_PTR res = 0;\r
197                 ::SendMessageTimeout(HWND_BROADCAST, WM_SETTINGCHANGE, 0, 0, SMTO_ABORTIFHUNG, 20, &res);\r
198                 CMessageBox::Show(NULL, IDS_SETTINGS_RESTARTSYSTEM, IDS_APPNAME, MB_ICONINFORMATION);\r
199         }\r
200         if (restart & ISettingsPropPage::Restart_Cache)\r
201         {\r
202                 DWORD_PTR res = 0;\r
203                 ::SendMessageTimeout(HWND_BROADCAST, WM_SETTINGCHANGE, 0, 0, SMTO_ABORTIFHUNG, 20, &res);\r
204                 // tell the cache to refresh everything\r
205                 HANDLE hPipe = CreateFile( \r
206                         GetCacheCommandPipeName(),              // pipe name \r
207                         GENERIC_READ |                                  // read and write access \r
208                         GENERIC_WRITE, \r
209                         0,                                                              // no sharing \r
210                         NULL,                                                   // default security attributes\r
211                         OPEN_EXISTING,                                  // opens existing pipe \r
212                         FILE_FLAG_OVERLAPPED,                   // default attributes \r
213                         NULL);                                                  // no template file \r
214 \r
215 \r
216                 if (hPipe != INVALID_HANDLE_VALUE) \r
217                 {\r
218                         // The pipe connected; change to message-read mode. \r
219                         DWORD dwMode; \r
220 \r
221                         dwMode = PIPE_READMODE_MESSAGE; \r
222                         if (SetNamedPipeHandleState( \r
223                                 hPipe,    // pipe handle \r
224                                 &dwMode,  // new pipe mode \r
225                                 NULL,     // don't set maximum bytes \r
226                                 NULL))    // don't set maximum time \r
227                         {\r
228                                 DWORD cbWritten; \r
229                                 TSVNCacheCommand cmd;\r
230                                 SecureZeroMemory(&cmd, sizeof(TSVNCacheCommand));\r
231                                 cmd.command = TSVNCACHECOMMAND_REFRESHALL;\r
232                                 BOOL fSuccess = WriteFile( \r
233                                         hPipe,                  // handle to pipe \r
234                                         &cmd,                   // buffer to write from \r
235                                         sizeof(cmd),    // number of bytes to write \r
236                                         &cbWritten,             // number of bytes written \r
237                                         NULL);                  // not overlapped I/O \r
238 \r
239                                 if (! fSuccess || sizeof(cmd) != cbWritten)\r
240                                 {\r
241                                         DisconnectNamedPipe(hPipe); \r
242                                         CloseHandle(hPipe); \r
243                                         hPipe = INVALID_HANDLE_VALUE;\r
244                                 }\r
245                                 if (hPipe != INVALID_HANDLE_VALUE)\r
246                                 {\r
247                                         // now tell the cache we don't need it's command thread anymore\r
248                                         DWORD cbWritten; \r
249                                         TSVNCacheCommand cmd;\r
250                                         SecureZeroMemory(&cmd, sizeof(TSVNCacheCommand));\r
251                                         cmd.command = TSVNCACHECOMMAND_END;\r
252                                         WriteFile( \r
253                                                 hPipe,                  // handle to pipe \r
254                                                 &cmd,                   // buffer to write from \r
255                                                 sizeof(cmd),    // number of bytes to write \r
256                                                 &cbWritten,             // number of bytes written \r
257                                                 NULL);                  // not overlapped I/O \r
258                                         DisconnectNamedPipe(hPipe); \r
259                                         CloseHandle(hPipe); \r
260                                         hPipe = INVALID_HANDLE_VALUE;\r
261                                 }\r
262                         }\r
263                         else\r
264                         {\r
265                                 ATLTRACE("SetNamedPipeHandleState failed"); \r
266                                 CloseHandle(hPipe);\r
267                         }\r
268                 }\r
269         }\r
270 }\r
271 \r
272 BEGIN_MESSAGE_MAP(CSettings, CTreePropSheet)\r
273         ON_WM_QUERYDRAGICON()\r
274         ON_WM_PAINT()\r
275 END_MESSAGE_MAP()\r
276 \r
277 BOOL CSettings::OnInitDialog()\r
278 {\r
279         BOOL bResult = CTreePropSheet::OnInitDialog();\r
280 \r
281         SetIcon(m_hIcon, TRUE);                 // Set big icon\r
282         SetIcon(m_hIcon, FALSE);                // Set small icon\r
283 \r
284         CenterWindow(CWnd::FromHandle(hWndExplorer));\r
285 \r
286         if(this->m_DefaultPage == _T("gitremote"))\r
287         {\r
288                 this->SetActivePage(this->m_pGitRemote);\r
289         }\r
290         if(this->m_DefaultPage == _T("main"))\r
291         {\r
292                 this->SetActivePage(this->m_pMainPage);\r
293         }\r
294         if(this->m_DefaultPage == _T("overlay"))\r
295         {\r
296                 this->SetActivePage(this->m_pOverlayPage);\r
297         }\r
298         if(this->m_DefaultPage == _T("overlays"))\r
299         {\r
300                 this->SetActivePage(this->m_pOverlaysPage);\r
301         }\r
302         if(this->m_DefaultPage == _T("proxy"))\r
303         {\r
304                 this->SetActivePage(this->m_pProxyPage);\r
305         }\r
306         \r
307         if(this->m_DefaultPage == _T("diff"))\r
308         {\r
309                 this->SetActivePage(this->m_pProgsDiffPage);\r
310         }\r
311         if(this->m_DefaultPage == _T("merge"))\r
312         {\r
313                 this->SetActivePage(this->m_pProgsMergePage);\r
314         }\r
315         if(this->m_DefaultPage == _T("unidiff"))\r
316         {\r
317                 this->SetActivePage(this->m_pProgsUniDiffPage);\r
318         }\r
319         if(this->m_DefaultPage == _T("look"))\r
320         {\r
321                 this->SetActivePage(this->m_pLookAndFeelPage);\r
322         }\r
323         if(this->m_DefaultPage == _T("dialog"))\r
324         {\r
325                 this->SetActivePage(this->m_pDialogsPage);\r
326         }\r
327         if(this->m_DefaultPage == _T("misc"))\r
328         {\r
329                 this->SetActivePage(this->m_pMiscPage);\r
330         }\r
331         if(this->m_DefaultPage == _T("graph"))\r
332         {\r
333                 this->SetActivePage(this->m_pRevisionGraphPage);\r
334         }\r
335 \r
336         if(this->m_DefaultPage == _T("color1"))\r
337         {\r
338                 this->SetActivePage(this->m_pColorsPage);\r
339         }\r
340         if(this->m_DefaultPage == _T("color2"))\r
341         {\r
342                 this->SetActivePage(this->m_pColorsPage2);\r
343         }\r
344         if(this->m_DefaultPage == _T("color3"))\r
345         {\r
346                 this->SetActivePage(this->m_pColorsPage3);\r
347         }\r
348         if(this->m_DefaultPage == _T("save"))\r
349         {\r
350                 this->SetActivePage(this->m_pSavedPage);\r
351         }\r
352 \r
353         return bResult;\r
354 }\r
355 \r
356 void CSettings::OnPaint()\r
357 {\r
358         if (IsIconic())\r
359         {\r
360                 CPaintDC dc(this); // device context for painting\r
361 \r
362                 SendMessage(WM_ICONERASEBKGND, reinterpret_cast<WPARAM>(dc.GetSafeHdc()), 0);\r
363 \r
364                 // Center icon in client rectangle\r
365                 int cxIcon = GetSystemMetrics(SM_CXICON);\r
366                 int cyIcon = GetSystemMetrics(SM_CYICON);\r
367                 CRect rect;\r
368                 GetClientRect(&rect);\r
369                 int x = (rect.Width() - cxIcon + 1) / 2;\r
370                 int y = (rect.Height() - cyIcon + 1) / 2;\r
371 \r
372                 // Draw the icon\r
373                 dc.DrawIcon(x, y, m_hIcon);\r
374         }\r
375         else\r
376         {\r
377                 CTreePropSheet::OnPaint();\r
378         }\r
379 }\r
380 \r
381 HCURSOR CSettings::OnQueryDragIcon()\r
382 {\r
383         return static_cast<HCURSOR>(m_hIcon);\r
384 }\r