1 /*
2  * Folder options.
3  *
4  * Copyright (C) 2016 Mark Jansen
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * version 2.1 of the License, or (at your option) any later version.
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with this library; if not, write to the Free Software
18  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
19  */
20 
21 #include <precomp.h>
22 #include <shdeprecated.h>
23 
24 
25 WINE_DEFAULT_DEBUG_CHANNEL(fprop);
26 
27 CFolderOptions::CFolderOptions()
28     :m_pSite(NULL)
29 {
30 }
31 
32 CFolderOptions::~CFolderOptions()
33 {
34 }
35 
36 /*************************************************************************
37  * FolderOptions IShellPropSheetExt interface
38  */
39 
40 INT_PTR CALLBACK FolderOptionsGeneralDlg(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam);
41 INT_PTR CALLBACK FolderOptionsViewDlg(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam);
42 INT_PTR CALLBACK FolderOptionsFileTypesDlg(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam);
43 
44 HRESULT STDMETHODCALLTYPE CFolderOptions::AddPages(LPFNSVADDPROPSHEETPAGE pfnAddPage, LPARAM lParam)
45 {
46     HPROPSHEETPAGE hPage;
47     LPARAM sheetparam = (LPARAM)static_cast<CFolderOptions*>(this);
48 
49     hPage = SH_CreatePropertySheetPage(IDD_FOLDER_OPTIONS_GENERAL, FolderOptionsGeneralDlg, sheetparam, NULL);
50     if (hPage == NULL)
51     {
52         ERR("Failed to create property sheet page FolderOptionsGeneral\n");
53         return E_FAIL;
54     }
55     if (!pfnAddPage(hPage, lParam))
56         return E_FAIL;
57 
58     hPage = SH_CreatePropertySheetPage(IDD_FOLDER_OPTIONS_VIEW, FolderOptionsViewDlg, sheetparam, NULL);
59     if (hPage == NULL)
60     {
61         ERR("Failed to create property sheet page FolderOptionsView\n");
62         return E_FAIL;
63     }
64     if (!pfnAddPage(hPage, lParam))
65         return E_FAIL;
66 
67     hPage = SH_CreatePropertySheetPage(IDD_FOLDER_OPTIONS_FILETYPES, FolderOptionsFileTypesDlg, sheetparam, NULL);
68     if (hPage == NULL)
69     {
70         ERR("Failed to create property sheet page FolderOptionsFileTypes\n");
71         return E_FAIL;
72     }
73     if (!pfnAddPage(hPage, lParam))
74         return E_FAIL;
75 
76     return S_OK;
77 }
78 
79 HRESULT STDMETHODCALLTYPE CFolderOptions::ReplacePage(EXPPS uPageID, LPFNSVADDPROPSHEETPAGE pfnReplaceWith, LPARAM lParam)
80 {
81     TRACE("(%p) (uPageID %u, pfnReplaceWith %p lParam %p\n", this, uPageID, pfnReplaceWith, lParam);
82     return E_NOTIMPL;
83 }
84 
85 /*************************************************************************
86  * FolderOptions IShellExtInit interface
87  */
88 
89 HRESULT STDMETHODCALLTYPE CFolderOptions::Initialize(PCIDLIST_ABSOLUTE pidlFolder, IDataObject *pdtobj, HKEY hkeyProgID)
90 {
91     return S_OK;
92 }
93 
94 
95 /*************************************************************************
96  * FolderOptions IObjectWithSite interface
97  */
98 HRESULT STDMETHODCALLTYPE CFolderOptions::SetSite(IUnknown *pUnkSite)
99 {
100     m_pSite = pUnkSite;
101     return S_OK;
102 }
103 
104 HRESULT STDMETHODCALLTYPE CFolderOptions::GetSite(REFIID riid, void **ppvSite)
105 {
106     return m_pSite ? m_pSite->QueryInterface(riid, ppvSite) : E_FAIL;
107 }
108 
109 /*************************************************************************
110  * FolderOptions helper methods
111  */
112 HRESULT CFolderOptions::HandleDefFolderSettings(int Action)
113 {
114     IBrowserService2 *bs2;
115     HRESULT hr = IUnknown_QueryService(m_pSite, SID_SShellBrowser, IID_PPV_ARG(IBrowserService2, &bs2));
116     if (SUCCEEDED(hr))
117     {
118         if (Action == DFSA_APPLY)
119         {
120             hr = bs2->SetAsDefFolderSettings();
121         }
122         else if (Action == DFSA_RESET)
123         {
124             // There does not seem to be a method in IBrowserService2 for this
125             IUnknown_Exec(bs2, CGID_DefView, DVCMDID_RESET_DEFAULTFOLDER_SETTINGS, OLECMDEXECOPT_DODEFAULT, NULL, NULL);
126         }
127         else
128         {
129             // FFSA_QUERY: hr is already correct
130         }
131         bs2->Release();
132     }
133 
134     if (Action == DFSA_RESET)
135     {
136         IGlobalFolderSettings *pgfs;
137         HRESULT hr = CoCreateInstance(CLSID_GlobalFolderSettings, NULL, CLSCTX_INPROC_SERVER,
138                                       IID_IGlobalFolderSettings, (void **)&pgfs);
139         if (SUCCEEDED(hr))
140         {
141             hr = pgfs->Set(NULL, 0, 0);
142             pgfs->Release();
143         }
144     }
145 
146     return hr;
147 }
148