OSDN Git Service

1a08e0ce37dc66adf46928b4220f2a8ad3190bf3
[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 \r
26 \r
27 IMPLEMENT_DYNAMIC(CSettings, CTreePropSheet)\r
28 CSettings::CSettings(UINT nIDCaption, CWnd* pParentWnd, UINT iSelectPage)\r
29         :CTreePropSheet(nIDCaption, pParentWnd, iSelectPage)\r
30 {\r
31         m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);\r
32         AddPropPages();\r
33 }\r
34 \r
35 CSettings::~CSettings()\r
36 {\r
37         RemovePropPages();\r
38 }\r
39 \r
40 void CSettings::AddPropPages()\r
41 {\r
42         m_pMainPage = new CSetMainPage();\r
43         m_pOverlayPage = new CSetOverlayPage();\r
44         m_pOverlaysPage = new CSetOverlayIcons();\r
45         m_pProxyPage = new CSetProxyPage();\r
46         m_pProgsDiffPage = new CSettingsProgsDiff();\r
47         m_pProgsMergePage = new CSettingsProgsMerge();\r
48         m_pProgsUniDiffPage = new CSettingsProgsUniDiff();\r
49         m_pLookAndFeelPage = new CSetLookAndFeelPage();\r
50         m_pDialogsPage = new CSetDialogs();\r
51         m_pMiscPage = new CSetMisc();\r
52         m_pRevisionGraphPage = new CSettingsRevisionGraph();\r
53 //      m_pLogCachePage = new CSetLogCache();\r
54 //      m_pLogCacheListPage = new CSettingsLogCaches();\r
55         m_pColorsPage = new CSettingsColors();\r
56     m_pColorsPage2 = new CSettingsColors2();\r
57     m_pColorsPage3 = new CSettingsColors3();\r
58         m_pSavedPage = new CSetSavedDataPage();\r
59 //      m_pHooksPage = new CSetHooks();\r
60         m_pBugTraqPage = new CSetBugTraq();\r
61         m_pTBlamePage = new CSettingsTBlame();\r
62         m_pGitConfig = new CSettingGitConfig();\r
63         m_pGitRemote = new CSettingGitRemote();\r
64 \r
65 \r
66         SetPageIcon(m_pMainPage, m_pMainPage->GetIconID());\r
67         SetPageIcon(m_pOverlayPage, m_pOverlayPage->GetIconID());\r
68         SetPageIcon(m_pOverlaysPage, m_pOverlaysPage->GetIconID());\r
69         SetPageIcon(m_pProxyPage, m_pProxyPage->GetIconID());\r
70         SetPageIcon(m_pProgsDiffPage, m_pProgsDiffPage->GetIconID());\r
71         SetPageIcon(m_pProgsMergePage, m_pProgsMergePage->GetIconID());\r
72         SetPageIcon(m_pProgsUniDiffPage, m_pProgsUniDiffPage->GetIconID());\r
73         SetPageIcon(m_pLookAndFeelPage, m_pLookAndFeelPage->GetIconID());\r
74         SetPageIcon(m_pDialogsPage, m_pDialogsPage->GetIconID());\r
75         SetPageIcon(m_pRevisionGraphPage, m_pRevisionGraphPage->GetIconID());\r
76         SetPageIcon(m_pMiscPage, m_pMiscPage->GetIconID());\r
77 ////    SetPageIcon(m_pLogCachePage, m_pLogCachePage->GetIconID());\r
78 //      SetPageIcon(m_pLogCacheListPage, m_pLogCacheListPage->GetIconID());\r
79         SetPageIcon(m_pColorsPage, m_pColorsPage->GetIconID());\r
80     SetPageIcon(m_pColorsPage2, m_pColorsPage2->GetIconID());\r
81     SetPageIcon(m_pColorsPage3, m_pColorsPage3->GetIconID());\r
82 \r
83         SetPageIcon(m_pSavedPage, m_pSavedPage->GetIconID());\r
84 //      SetPageIcon(m_pHooksPage, m_pHooksPage->GetIconID());\r
85 \r
86         SetPageIcon(m_pGitConfig, m_pGitConfig->GetIconID());\r
87         SetPageIcon(m_pGitRemote, m_pGitRemote->GetIconID());\r
88         SetPageIcon(m_pBugTraqPage, m_pBugTraqPage->GetIconID());\r
89         SetPageIcon(m_pTBlamePage, m_pTBlamePage->GetIconID());\r
90 \r
91         AddPage(m_pMainPage);\r
92         AddPage(m_pOverlayPage);\r
93         AddPage(m_pOverlaysPage);\r
94         AddPage(m_pProxyPage);\r
95         AddPage(m_pProgsDiffPage);\r
96         AddPage(m_pProgsMergePage);\r
97         AddPage(m_pProgsUniDiffPage);\r
98         AddPage(m_pLookAndFeelPage);\r
99         AddPage(m_pDialogsPage);\r
100         AddPage(m_pMiscPage);\r
101         AddPage(m_pRevisionGraphPage);\r
102         AddPage(m_pColorsPage);\r
103         AddPage(m_pColorsPage2);\r
104         AddPage(m_pColorsPage3);\r
105         AddPage(m_pSavedPage);\r
106 \r
107         AddPage(m_pGitConfig);\r
108         AddPage(m_pGitRemote);\r
109 //      AddPage(m_pGitRemotem_pLogCachePage);\r
110 //    AddPage(m_pLogCacheListPage);\r
111 //      AddPage(m_pHooksPage);\r
112         AddPage(m_pBugTraqPage);\r
113         AddPage(m_pTBlamePage);\r
114 }\r
115 \r
116 void CSettings::RemovePropPages()\r
117 {\r
118         delete m_pMainPage;\r
119         delete m_pOverlayPage;\r
120         delete m_pOverlaysPage;\r
121         delete m_pProxyPage;\r
122         delete m_pProgsDiffPage;\r
123         delete m_pProgsMergePage;\r
124         delete m_pProgsUniDiffPage;\r
125         delete m_pLookAndFeelPage;\r
126         delete m_pDialogsPage;\r
127     delete m_pRevisionGraphPage;\r
128         delete m_pMiscPage;\r
129 ////    delete m_pLogCachePage;\r
130 ////    delete m_pLogCacheListPage;\r
131         delete m_pColorsPage;\r
132         delete m_pColorsPage2;\r
133         delete m_pColorsPage3;\r
134         delete m_pSavedPage;\r
135 //      delete m_pHooksPage;\r
136         delete m_pBugTraqPage;\r
137         delete m_pTBlamePage;\r
138 \r
139         delete m_pGitConfig;\r
140         delete m_pGitRemote;\r
141 \r
142 }\r
143 \r
144 void CSettings::HandleRestart()\r
145 {\r
146         int restart = ISettingsPropPage::Restart_None;\r
147         restart |= m_pMainPage->GetRestart();\r
148         restart |= m_pOverlayPage->GetRestart();\r
149         restart |= m_pOverlaysPage->GetRestart();\r
150         restart |= m_pProxyPage->GetRestart();\r
151         restart |= m_pProgsDiffPage->GetRestart();\r
152         restart |= m_pProgsMergePage->GetRestart();\r
153         restart |= m_pProgsUniDiffPage->GetRestart();\r
154         restart |= m_pLookAndFeelPage->GetRestart();\r
155         restart |= m_pDialogsPage->GetRestart();\r
156     restart |= m_pRevisionGraphPage->GetRestart();\r
157         restart |= m_pMiscPage->GetRestart();\r
158 ////    restart |= m_pLogCachePage->GetRestart();\r
159 //      restart |= m_pLogCacheListPage->GetRestart();\r
160         restart |= m_pColorsPage->GetRestart();\r
161         restart |= m_pColorsPage2->GetRestart();\r
162         restart |= m_pColorsPage3->GetRestart();\r
163         restart |= m_pSavedPage->GetRestart();\r
164 ////    restart |= m_pHooksPage->GetRestart();\r
165         restart |= m_pBugTraqPage->GetRestart();\r
166         restart |= m_pTBlamePage->GetRestart();\r
167 \r
168         restart |= m_pGitConfig->GetRestart();\r
169         restart |= m_pGitRemote->GetRestart();\r
170 \r
171         if (restart & ISettingsPropPage::Restart_System)\r
172         {\r
173                 DWORD_PTR res = 0;\r
174                 ::SendMessageTimeout(HWND_BROADCAST, WM_SETTINGCHANGE, 0, 0, SMTO_ABORTIFHUNG, 20, &res);\r
175                 CMessageBox::Show(NULL, IDS_SETTINGS_RESTARTSYSTEM, IDS_APPNAME, MB_ICONINFORMATION);\r
176         }\r
177         if (restart & ISettingsPropPage::Restart_Cache)\r
178         {\r
179                 DWORD_PTR res = 0;\r
180                 ::SendMessageTimeout(HWND_BROADCAST, WM_SETTINGCHANGE, 0, 0, SMTO_ABORTIFHUNG, 20, &res);\r
181                 // tell the cache to refresh everything\r
182                 HANDLE hPipe = CreateFile( \r
183                         GetCacheCommandPipeName(),              // pipe name \r
184                         GENERIC_READ |                                  // read and write access \r
185                         GENERIC_WRITE, \r
186                         0,                                                              // no sharing \r
187                         NULL,                                                   // default security attributes\r
188                         OPEN_EXISTING,                                  // opens existing pipe \r
189                         FILE_FLAG_OVERLAPPED,                   // default attributes \r
190                         NULL);                                                  // no template file \r
191 \r
192 \r
193                 if (hPipe != INVALID_HANDLE_VALUE) \r
194                 {\r
195                         // The pipe connected; change to message-read mode. \r
196                         DWORD dwMode; \r
197 \r
198                         dwMode = PIPE_READMODE_MESSAGE; \r
199                         if (SetNamedPipeHandleState( \r
200                                 hPipe,    // pipe handle \r
201                                 &dwMode,  // new pipe mode \r
202                                 NULL,     // don't set maximum bytes \r
203                                 NULL))    // don't set maximum time \r
204                         {\r
205                                 DWORD cbWritten; \r
206                                 TSVNCacheCommand cmd;\r
207                                 SecureZeroMemory(&cmd, sizeof(TSVNCacheCommand));\r
208                                 cmd.command = TSVNCACHECOMMAND_REFRESHALL;\r
209                                 BOOL fSuccess = WriteFile( \r
210                                         hPipe,                  // handle to pipe \r
211                                         &cmd,                   // buffer to write from \r
212                                         sizeof(cmd),    // number of bytes to write \r
213                                         &cbWritten,             // number of bytes written \r
214                                         NULL);                  // not overlapped I/O \r
215 \r
216                                 if (! fSuccess || sizeof(cmd) != cbWritten)\r
217                                 {\r
218                                         DisconnectNamedPipe(hPipe); \r
219                                         CloseHandle(hPipe); \r
220                                         hPipe = INVALID_HANDLE_VALUE;\r
221                                 }\r
222                                 if (hPipe != INVALID_HANDLE_VALUE)\r
223                                 {\r
224                                         // now tell the cache we don't need it's command thread anymore\r
225                                         DWORD cbWritten; \r
226                                         TSVNCacheCommand cmd;\r
227                                         SecureZeroMemory(&cmd, sizeof(TSVNCacheCommand));\r
228                                         cmd.command = TSVNCACHECOMMAND_END;\r
229                                         WriteFile( \r
230                                                 hPipe,                  // handle to pipe \r
231                                                 &cmd,                   // buffer to write from \r
232                                                 sizeof(cmd),    // number of bytes to write \r
233                                                 &cbWritten,             // number of bytes written \r
234                                                 NULL);                  // not overlapped I/O \r
235                                         DisconnectNamedPipe(hPipe); \r
236                                         CloseHandle(hPipe); \r
237                                         hPipe = INVALID_HANDLE_VALUE;\r
238                                 }\r
239                         }\r
240                         else\r
241                         {\r
242                                 ATLTRACE("SetNamedPipeHandleState failed"); \r
243                                 CloseHandle(hPipe);\r
244                         }\r
245                 }\r
246         }\r
247 }\r
248 \r
249 BEGIN_MESSAGE_MAP(CSettings, CTreePropSheet)\r
250         ON_WM_QUERYDRAGICON()\r
251         ON_WM_PAINT()\r
252 END_MESSAGE_MAP()\r
253 \r
254 BOOL CSettings::OnInitDialog()\r
255 {\r
256         BOOL bResult = CTreePropSheet::OnInitDialog();\r
257 \r
258         SetIcon(m_hIcon, TRUE);                 // Set big icon\r
259         SetIcon(m_hIcon, FALSE);                // Set small icon\r
260 \r
261         CenterWindow(CWnd::FromHandle(hWndExplorer));\r
262         return bResult;\r
263 }\r
264 \r
265 void CSettings::OnPaint()\r
266 {\r
267         if (IsIconic())\r
268         {\r
269                 CPaintDC dc(this); // device context for painting\r
270 \r
271                 SendMessage(WM_ICONERASEBKGND, reinterpret_cast<WPARAM>(dc.GetSafeHdc()), 0);\r
272 \r
273                 // Center icon in client rectangle\r
274                 int cxIcon = GetSystemMetrics(SM_CXICON);\r
275                 int cyIcon = GetSystemMetrics(SM_CYICON);\r
276                 CRect rect;\r
277                 GetClientRect(&rect);\r
278                 int x = (rect.Width() - cxIcon + 1) / 2;\r
279                 int y = (rect.Height() - cyIcon + 1) / 2;\r
280 \r
281                 // Draw the icon\r
282                 dc.DrawIcon(x, y, m_hIcon);\r
283         }\r
284         else\r
285         {\r
286                 CTreePropSheet::OnPaint();\r
287         }\r
288 }\r
289 \r
290 HCURSOR CSettings::OnQueryDragIcon()\r
291 {\r
292         return static_cast<HCURSOR>(m_hIcon);\r
293 }\r