1 /*****************************************************************************
2  * Copyright (C) 2010 Jan Lepper <krusader@users.sourceforge.net>            *
3  * Copyright (C) 2010-2019 Krusader Krew [https://krusader.org]              *
4  *                                                                           *
5  * This file is part of Krusader [https://krusader.org].                     *
6  *                                                                           *
7  * Krusader is free software: you can redistribute it and/or modify          *
8  * it under the terms of the GNU General Public License as published by      *
9  * the Free Software Foundation, either version 2 of the License, or         *
10  * (at your option) any later version.                                       *
11  *                                                                           *
12  * Krusader is distributed in the hope that it will be useful,               *
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of            *
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the             *
15  * GNU General Public License for more details.                              *
16  *                                                                           *
17  * You should have received a copy of the GNU General Public License         *
18  * along with Krusader.  If not, see [http://www.gnu.org/licenses/].         *
19  *****************************************************************************/
20 
21 #include "kgpanel.h"
22 #include "../defaults.h"
23 #include "../Dialogs/krdialogs.h"
24 
25 // QtGui
26 #include <QValidator>
27 // QtWidgets
28 #include <QTabWidget>
29 #include <QFrame>
30 #include <QGridLayout>
31 #include <QLabel>
32 #include <QVBoxLayout>
33 
34 #include <KI18n/KLocalizedString>
35 #include <KWidgetsAddons/KMessageBox>
36 
37 #include "../GUI/krtreewidget.h"
38 #include "../Panel/krsearchbar.h"
39 #include "../Panel/PanelView/krselectionmode.h"
40 #include "../Panel/PanelView/krview.h"
41 #include "../Panel/PanelView/krviewfactory.h"
42 #include "../Panel/krlayoutfactory.h"
43 
44 enum {
45     PAGE_GENERAL = 0,
46     PAGE_VIEW,
47     PAGE_PANELTOOLBAR,
48     PAGE_MOUSE,
49     PAGE_MEDIA_MENU,
50     PAGE_LAYOUT
51 };
52 
53 
KgPanel(bool first,QWidget * parent)54 KgPanel::KgPanel(bool first, QWidget* parent) :
55         KonfiguratorPage(first, parent)
56 {
57     tabWidget = new QTabWidget(this);
58     setWidget(tabWidget);
59     setWidgetResizable(true);
60 
61     setupGeneralTab();
62     setupPanelTab();
63     setupButtonsTab();
64     setupMouseModeTab();
65     setupMediaMenuTab();
66     setupLayoutTab();
67 }
68 
69 // ---------------------------------------------------------------------------------------
70 // ---------------------------- General TAB ----------------------------------------------
71 // ---------------------------------------------------------------------------------------
setupGeneralTab()72 void KgPanel::setupGeneralTab()
73 {
74     QScrollArea *scrollArea = new QScrollArea(tabWidget);
75     QWidget *tab = new QWidget(scrollArea);
76     scrollArea->setFrameStyle(QFrame::NoFrame);
77     scrollArea->setWidget(tab);
78     scrollArea->setWidgetResizable(true);
79     tabWidget->addTab(scrollArea, i18n("General"));
80 
81     QVBoxLayout *layout = new QVBoxLayout(tab);
82     layout->setSpacing(6);
83     layout->setContentsMargins(11, 11, 11, 11);
84 
85 // ---------------------------------------------------------------------------------------
86 // ------------------------------- Navigator bar -------------------------------------
87 // ---------------------------------------------------------------------------------------
88         QGroupBox *groupBox = createFrame(i18n("Navigator bar"), tab);
89         QGridLayout *gridLayout = createGridLayout(groupBox);
90 
91         KONFIGURATOR_CHECKBOX_PARAM navigatorbar_settings[] = {
92             // cfg_class, cfg_name, default, text, restart, tooltip
93             {"Look&Feel", "Navigator Edit Mode", false, i18n("Edit Mode by default"),       true, i18n("Show editable path in Navigator bar by default") },
94             {"Look&Feel", "Navigator Full Path", false, i18n("Show full path by default"),  true, i18n("Always show full path in Navigator bar by default.") },
95         };
96         KonfiguratorCheckBoxGroup* cbs = createCheckBoxGroup(2, 0, navigatorbar_settings, 2 /*count*/, groupBox, PAGE_GENERAL);
97         gridLayout->addWidget(cbs, 0, 0);
98 
99         layout->addWidget(groupBox);
100 
101 // ---------------------------------------------------------------------------------------
102 // ------------------------------- Operation ---------------------------------------------
103 // ---------------------------------------------------------------------------------------
104     groupBox = createFrame(i18n("Operation"), tab);
105     gridLayout = createGridLayout(groupBox);
106 
107     KONFIGURATOR_CHECKBOX_PARAM operation_settings[] = { // cfg_class, cfg_name, default, text, restart, tooltip
108         {"Look&Feel", "Mark Dirs",            _MarkDirs,          i18n("Autoselect folders"),   false,  i18n("When matching the select criteria, not only files will be selected, but also folders.") },
109         {"Look&Feel", "Rename Selects Extension", true,          i18n("Rename selects extension"),   false,  i18n("When renaming a file, the whole text is selected. If you want Total-Commander like renaming of just the name, without extension, uncheck this option.") },
110         {"Look&Feel", "UnselectBeforeOperation", _UnselectBeforeOperation, i18n("Unselect files before copy/move"), false, i18n("Unselect files, which are to be copied/moved, before the operation starts.") },
111         {"Look&Feel", "FilterDialogRemembersSettings", _FilterDialogRemembersSettings, i18n("Filter dialog remembers settings"), false, i18n("The filter dialog is opened with the last filter settings that where applied to the panel.") },
112     };
113     cbs = createCheckBoxGroup(2, 0, operation_settings, 4 /*count*/, groupBox, PAGE_GENERAL);
114     gridLayout->addWidget(cbs, 0, 0);
115 
116     layout->addWidget(groupBox);
117 
118 // ---------------------------------------------------------------------------------------
119 // ------------------------------ Tabs ---------------------------------------------------
120 // ---------------------------------------------------------------------------------------
121     groupBox = createFrame(i18n("Tabs"), tab);
122     gridLayout = createGridLayout(groupBox);
123 
124     KONFIGURATOR_CHECKBOX_PARAM tabbar_settings[] = { //   cfg_class  cfg_name                default             text                              restart tooltip
125         {"Look&Feel", "Fullpath Tab Names",   _FullPathTabNames,  i18n("Use full path tab names"), true ,  i18n("Display the full path in the folder tabs. By default only the last part of the path is displayed.") },
126         {"Look&Feel", "Show Tab Buttons",   true,  i18n("Show new/close tab buttons"), true ,  i18n("Show the new/close tab buttons.") },
127     };
128     cbs = createCheckBoxGroup(2, 0, tabbar_settings, 2 /*count*/, groupBox, PAGE_GENERAL);
129     gridLayout->addWidget(cbs, 0, 0, 1, 2);
130 
131 // -----------------  Tab Bar position ----------------------------------
132     QHBoxLayout *hbox = new QHBoxLayout();
133 
134     hbox->addWidget(new QLabel(i18n("Tab Bar position:"), groupBox));
135 
136     KONFIGURATOR_NAME_VALUE_PAIR positions[] = {
137         { i18n("Top"),      "top" },
138         { i18n("Bottom"),   "bottom" }
139     };
140 
141     KonfiguratorComboBox *cmb = createComboBox("Look&Feel", "Tab Bar Position",
142                                 "bottom", positions, 2, groupBox, true, false, PAGE_GENERAL);
143 
144     hbox->addWidget(cmb);
145     gridLayout->addLayout(hbox, 1, 0, Qt::AlignLeft);
146 
147 // -----------------  Show Tab bar ----------------------------------
148     KonfiguratorCheckBox *checkBox = createCheckBox("Look&Feel", "Show Tab Bar On Single Tab", true,
149                                                     i18n("Show Tab Bar on single tab"), groupBox,
150                                                     true, i18n("Show the tab bar with only one tab."));
151     gridLayout->addWidget(checkBox, 1, 1, Qt::AlignLeft);
152 
153     layout->addWidget(groupBox);
154 
155 // ---------------------------------------------------------------------------------------
156 // -----------------------------  Search bar  --------------------------------------------
157 // ---------------------------------------------------------------------------------------
158     groupBox = createFrame(i18n("Search bar"), tab);
159     gridLayout = createGridLayout(groupBox);
160 
161     KONFIGURATOR_CHECKBOX_PARAM quicksearch[] = { //   cfg_class  cfg_name                default             text                              restart tooltip
162         {"Look&Feel", "New Style Quicksearch",  _NewStyleQuicksearch, i18n("Start by typing"), false,  i18n("Open search bar and start searching by typing in panel.") },
163         {"Look&Feel", "Case Sensitive Quicksearch",  _CaseSensitiveQuicksearch, i18n("Case sensitive"), false,  i18n("Search must match case.") },
164         {"Look&Feel", "Up/Down Cancels Quicksearch",  false, i18n("Up/Down cancels search"), false,  i18n("Pressing the Up/Down buttons closes the search bar (only in search mode).") },
165         {"Look&Feel", "Navigation with Right Arrow Quicksearch", _NavigationWithRightArrowQuicksearch, i18n("Directory navigation with Right Arrow"), false, i18n("Pressing the Right button enters directory if no search text editing intention is captured.") },
166     };
167 
168     cbs = createCheckBoxGroup(2, 0, quicksearch, 4 /*count*/, groupBox, PAGE_GENERAL);
169     gridLayout->addWidget(cbs, 0, 0, 1, -1);
170 
171     // -------------- Search bar position -----------------------
172 
173     hbox = new QHBoxLayout();
174     hbox->addWidget(new QLabel(i18n("Position:"), groupBox));
175     cmb = createComboBox("Look&Feel", "Quicksearch Position",
176                             "bottom", positions, 2, groupBox, true, false, PAGE_GENERAL);
177     hbox->addWidget(cmb);
178     hbox->addWidget(createSpacer(groupBox));
179     gridLayout->addLayout(hbox, 1, 0);
180 
181     // -------------- Default search mode -----------------------
182 
183     hbox = new QHBoxLayout();
184     hbox->addWidget(new QLabel(i18n("Default mode:"), groupBox));
185     KONFIGURATOR_NAME_VALUE_PAIR modes[] = {
186         {i18n("Search"), QString::number(KrSearchBar::MODE_SEARCH)},
187         {i18n("Select"), QString::number(KrSearchBar::MODE_SELECT)},
188         {i18n("Filter"), QString::number(KrSearchBar::MODE_FILTER)}};
189     cmb = createComboBox("Look&Feel", "Default Search Mode",
190                          QString::number(KrSearchBar::MODE_SEARCH), modes, 3, groupBox, true, false,
191                          PAGE_GENERAL);
192     cmb->setToolTip(i18n("Set the default mode on first usage"));
193     hbox->addWidget(cmb);
194     hbox->addWidget(createSpacer(groupBox));
195     gridLayout->addLayout(hbox, 1, 1);
196 
197     layout->addWidget(groupBox);
198 
199 // --------------------------------------------------------------------------------------------
200 // ------------------------------- Bookmark search settings ----------------------------------
201 // --------------------------------------------------------------------------------------------
202     groupBox = createFrame(i18n("Bookmark Search"), tab);
203     gridLayout = createGridLayout(groupBox);
204 
205     KONFIGURATOR_CHECKBOX_PARAM bookmarkSearchSettings[] =
206     {
207         {"Look&Feel", "Always show search bar", true, i18n("Always show search bar"), false, i18n("Make bookmark search bar always visible") },
208         {"Look&Feel", "Search in special items", false, i18n("Search in special items"), false, i18n("Bookmark search is also applied to special items in bookmark menu like Trash, Popular URLs, Jump Back, etc.") },
209     };
210     KonfiguratorCheckBoxGroup *bookmarkSearchSettingsGroup = createCheckBoxGroup(2, 0, bookmarkSearchSettings,
211                                                                                  2 /*count*/, groupBox, PAGE_GENERAL);
212     gridLayout->addWidget(bookmarkSearchSettingsGroup, 1, 0, 1, 2);
213     layout->addWidget(groupBox);
214 
215 // --------------------------------------------------------------------------------------------
216 // ------------------------------- Status/Totalsbar settings ----------------------------------
217 // --------------------------------------------------------------------------------------------
218     groupBox = createFrame(i18n("Status/Totalsbar"), tab);
219     gridLayout = createGridLayout(groupBox);
220 
221     KONFIGURATOR_CHECKBOX_PARAM barSettings[] =
222     {
223         {"Look&Feel", "Show Size In Bytes", false, i18n("Show size in bytes too"), true,  i18n("Show size in bytes too") },
224         {"Look&Feel", "ShowSpaceInformation", true, i18n("Show space information"), true,  i18n("Show free/total space on the device") },
225     };
226     KonfiguratorCheckBoxGroup *barSett = createCheckBoxGroup(2, 0, barSettings,
227                                           2 /*count*/, groupBox, PAGE_GENERAL);
228     gridLayout->addWidget(barSett, 1, 0, 1, 2);
229 
230     layout->addWidget(groupBox);
231 }
232 
233 // --------------------------------------------------------------------------------------------
234 // ------------------------------------ Layout Tab --------------------------------------------
235 // --------------------------------------------------------------------------------------------
setupLayoutTab()236 void KgPanel::setupLayoutTab()
237 {
238     QScrollArea *scrollArea = new QScrollArea(tabWidget);
239     QWidget *tab = new QWidget(scrollArea);
240     scrollArea->setFrameStyle(QFrame::NoFrame);
241     scrollArea->setWidget(tab);
242     scrollArea->setWidgetResizable(true);
243     tabWidget->addTab(scrollArea, i18n("Layout"));
244 
245     QGridLayout *grid = createGridLayout(tab);
246 
247     QStringList layoutNames = KrLayoutFactory::layoutNames();
248     int numLayouts = layoutNames.count();
249 
250     grid->addWidget(createSpacer(tab), 0, 2);
251 
252     QLabel *l = new QLabel(i18n("Layout:"), tab);
253     l->setAlignment(Qt::AlignRight | Qt::AlignVCenter);
254     grid->addWidget(l, 0, 0);
255     KONFIGURATOR_NAME_VALUE_PAIR *layouts = new KONFIGURATOR_NAME_VALUE_PAIR[numLayouts];
256     for (int i = 0; i != numLayouts; i++) {
257         layouts[ i ].text = KrLayoutFactory::layoutDescription(layoutNames[i]);
258         layouts[ i ].value = layoutNames[i];
259     }
260     KonfiguratorComboBox *cmb = createComboBox("PanelLayout", "Layout", "default",
261                          layouts, numLayouts, tab, true, false, PAGE_LAYOUT);
262     grid->addWidget(cmb, 0, 1);
263     delete [] layouts;
264 
265     l = new QLabel(i18n("Frame Color:"), tab);
266     l->setAlignment(Qt::AlignRight | Qt::AlignVCenter);
267     grid->addWidget(l, 1, 0);
268     KONFIGURATOR_NAME_VALUE_PAIR frameColor[] = {
269         { i18nc("Frame color", "Defined by Layout"), "default" },
270         { i18nc("Frame color", "None"), "none" },
271         { i18nc("Frame color", "Statusbar"), "Statusbar" }
272     };
273     cmb = createComboBox("PanelLayout", "FrameColor",
274                             "default", frameColor, 3, tab, true, false, PAGE_LAYOUT);
275     grid->addWidget(cmb, 1, 1);
276 
277 
278     l = new QLabel(i18n("Frame Shape:"), tab);
279     l->setAlignment(Qt::AlignRight | Qt::AlignVCenter);
280     grid->addWidget(l, 2, 0);
281     KONFIGURATOR_NAME_VALUE_PAIR frameShape[] = {
282         { i18nc("Frame shape", "Defined by Layout"), "default" },
283         { i18nc("Frame shape", "None"), "NoFrame" },
284         { i18nc("Frame shape", "Box"), "Box" },
285         { i18nc("Frame shape", "Panel"), "Panel" },
286     };
287     cmb = createComboBox("PanelLayout", "FrameShape",
288                             "default", frameShape, 4, tab, true, false, PAGE_LAYOUT);
289     grid->addWidget(cmb, 2, 1);
290 
291 
292     l = new QLabel(i18n("Frame Shadow:"), tab);
293     l->setAlignment(Qt::AlignRight | Qt::AlignVCenter);
294     grid->addWidget(l, 3, 0);
295     KONFIGURATOR_NAME_VALUE_PAIR frameShadow[] = {
296         { i18nc("Frame shadow", "Defined by Layout"), "default" },
297         { i18nc("Frame shadow", "None"), "Plain" },
298         { i18nc("Frame shadow", "Raised"), "Raised" },
299         { i18nc("Frame shadow", "Sunken"), "Sunken" },
300     };
301     cmb = createComboBox("PanelLayout", "FrameShadow",
302                             "default", frameShadow, 4, tab, true, false, PAGE_LAYOUT);
303     grid->addWidget(cmb, 3, 1);
304 }
305 
setupView(KrViewInstance * instance,QWidget * parent)306 void KgPanel::setupView(KrViewInstance *instance, QWidget *parent)
307 {
308     QGridLayout *grid = createGridLayout(parent);
309 
310 // -------------------- Filelist icon size ----------------------------------
311     QHBoxLayout *hbox = new QHBoxLayout();
312 
313     hbox->addWidget(new QLabel(i18n("Default icon size:"), parent));
314 
315     KONFIGURATOR_NAME_VALUE_PAIR *iconSizes = new KONFIGURATOR_NAME_VALUE_PAIR[KrView::iconSizes.count()];
316     for(int i = 0; i < KrView::iconSizes.count(); i++)
317         iconSizes[i].text =  iconSizes[i].value = QString::number(KrView::iconSizes[i]);
318     KonfiguratorComboBox *cmb = createComboBox(instance->name(), "IconSize", _FilelistIconSize, iconSizes, KrView::iconSizes.count(), parent, true, true, PAGE_VIEW);
319     delete [] iconSizes;
320     cmb->lineEdit()->setValidator(new QRegExpValidator(QRegExp("[1-9]\\d{0,1}"), cmb));
321     hbox->addWidget(cmb);
322 
323     hbox->addWidget(createSpacer(parent));
324 
325     grid->addLayout(hbox, 1, 0);
326 
327 //--------------------------------------------------------------------
328     KONFIGURATOR_CHECKBOX_PARAM iconSettings[] =
329         //   cfg_class             cfg_name        default       text            restart        tooltip
330     {
331         {instance->name(), "With Icons",      _WithIcons,   i18n("Use icons in the filenames"), true,  i18n("Show the icons for filenames and folders.") },
332         {instance->name(), "ShowPreviews", false, i18n("Show previews by default"), false, i18n("Show previews of files and folders.") },
333     };
334 
335     KonfiguratorCheckBoxGroup *iconSett = createCheckBoxGroup(2, 0, iconSettings, 2 /*count*/, parent, PAGE_VIEW);
336 
337     grid->addWidget(iconSett, 2, 0, 1, 2);
338 }
339 
340 // ----------------------------------------------------------------------------------
341 //  ---------------------------- VIEW TAB -------------------------------------------
342 // ----------------------------------------------------------------------------------
setupPanelTab()343 void KgPanel::setupPanelTab()
344 {
345     QScrollArea *scrollArea = new QScrollArea(tabWidget);
346     QWidget *tab_panel = new QWidget(scrollArea);
347     scrollArea->setFrameStyle(QFrame::NoFrame);
348     scrollArea->setWidget(tab_panel);
349     scrollArea->setWidgetResizable(true);
350     tabWidget->addTab(scrollArea, i18n("View"));
351 
352     QGridLayout *panelLayout = new QGridLayout(tab_panel);
353     panelLayout->setSpacing(6);
354     panelLayout->setContentsMargins(11, 11, 11, 11);
355     QGroupBox *panelGrp = createFrame(i18n("General"), tab_panel);
356     panelLayout->addWidget(panelGrp, 0, 0);
357     QGridLayout *panelGrid = createGridLayout(panelGrp);
358 
359     // ----------------------------------------------------------------------------------
360     //  ---------------------------- General settings -----------------------------------
361     // ----------------------------------------------------------------------------------
362 
363     // -------------------- Panel Font ----------------------------------
364     QHBoxLayout *hbox = new QHBoxLayout();
365 
366     QHBoxLayout *fontLayout = new QHBoxLayout();
367     fontLayout->addWidget(new QLabel(i18n("View font:"), panelGrp));
368     KonfiguratorFontChooser *chsr =
369         createFontChooser("Look&Feel", "Filelist Font", _FilelistFont, panelGrp, true, PAGE_VIEW);
370     fontLayout->addWidget(chsr);
371     fontLayout->addStretch(1);
372     hbox->addLayout(fontLayout, 1);
373 
374     // -------------------- Panel Tooltip ----------------------------------
375     QHBoxLayout *tooltipLayout = new QHBoxLayout();
376     QLabel *tooltipLabel = new QLabel(i18n("Tooltip delay (msec):"));
377     tooltipLabel->setWhatsThis(i18n("The duration after a tooltip is shown for a file item, in "
378                                     "milliseconds. Set a negative value to disable tooltips."));
379     tooltipLayout->addWidget(tooltipLabel);
380     KonfiguratorSpinBox *tooltipSpinBox = createSpinBox("Look&Feel", "Panel Tooltip Delay", 1000,
381                                                         -100, 5000, panelGrp, false, PAGE_VIEW);
382     tooltipSpinBox->setSingleStep(100);
383     tooltipLayout->addWidget(tooltipSpinBox);
384     tooltipLayout->addStretch(1);
385     hbox->addLayout(tooltipLayout, 1);
386 
387     panelGrid->addLayout(hbox, 1, 0);
388 
389 
390     // -------------------- General options ----------------------------------
391     KONFIGURATOR_CHECKBOX_PARAM panelSettings[] =
392         //   cfg_class  cfg_name                default text                                  restart tooltip
393     {
394         {"Look&Feel", "Human Readable Size",            _HumanReadableSize,      i18n("Use human-readable file size"), true ,  i18n("File sizes are displayed in B, KB, MB and GB, not just in bytes.") },
395         {"Look&Feel", "Show Hidden",                    _ShowHidden,             i18n("Show hidden files"),      false,  i18n("Display files beginning with a dot.") },
396         {"Look&Feel", "Numeric permissions",            _NumericPermissions,     i18n("Numeric Permissions"), true,  i18n("Show octal numbers (0755) instead of the standard permissions (rwxr-xr-x) in the permission column.") },
397         {"Look&Feel", "Load User Defined Folder Icons", _UserDefinedFolderIcons, i18n("Load the user defined folder icons"), true ,  i18n("Load the user defined folder icons (can cause decrease in performance).") },
398         {"Look&Feel", "Always Show Current Item",       _AlwaysShowCurrentItem,  i18n("Always show current item"), false,  i18n("Show current item border decoration in inactive panel.") },
399     };
400 
401     KonfiguratorCheckBoxGroup *panelSett = createCheckBoxGroup(2, 0, panelSettings, 5 /*count*/, panelGrp, PAGE_VIEW);
402 
403     panelGrid->addWidget(panelSett, 3, 0, 1, 2);
404 
405     // =========================================================
406     panelGrid->addWidget(createLine(panelGrp), 4, 0);
407 
408     // ------------------------ Sort Method ----------------------------------
409 
410     hbox = new QHBoxLayout();
411 
412     hbox->addWidget(new QLabel(i18n("Sort method:"), panelGrp));
413 
414     KONFIGURATOR_NAME_VALUE_PAIR sortMethods[] = {{ i18n("Alphabetical"),                QString::number(KrViewProperties::Alphabetical) },
415         { i18n("Alphabetical and numbers"),    QString::number(KrViewProperties::AlphabeticalNumbers) },
416         { i18n("Character code"),              QString::number(KrViewProperties::CharacterCode) },
417         { i18n("Character code and numbers"),  QString::number(KrViewProperties::CharacterCodeNumbers) },
418         { i18nc("Krusader sort", "Krusader"),  QString::number(KrViewProperties::Krusader) }
419     };
420     KonfiguratorComboBox *cmb = createComboBox("Look&Feel", "Sort method", QString::number(_DefaultSortMethod),
421                             sortMethods, 5, panelGrp, true, false, PAGE_VIEW);
422     hbox->addWidget(cmb);
423     hbox->addWidget(createSpacer(panelGrp));
424 
425     panelGrid->addLayout(hbox, 5, 0);
426 
427     // ------------------------ Sort Options ----------------------------------
428     KONFIGURATOR_CHECKBOX_PARAM sortSettings[] =
429         // cfg_class, cfg_name, default, text, restart, tooltip
430     {
431         {"Look&Feel", "Case Sensative Sort", _CaseSensativeSort, i18n("Case sensitive sorting"), true,
432             i18n("All files beginning with capital letters appear before files beginning with non-capital letters (UNIX default).") },
433         {"Look&Feel", "Show Directories First", true, i18n("Show folders first"), true, 0 },
434         {"Look&Feel", "Always sort dirs by name", false, i18n("Always sort dirs by name"), true,
435             i18n("Folders are sorted by name, regardless of the sort column.") },
436         {"Look&Feel", "Locale Aware Sort", true, i18n("Locale aware sorting"), true,
437             i18n("The sorting is performed in a locale- and also platform-dependent manner. Can be slow.") },
438     };
439 
440     KonfiguratorCheckBoxGroup *sortSett = createCheckBoxGroup(2, 0, sortSettings,
441                                           4 /*count*/, panelGrp, PAGE_VIEW);
442     sortSett->find("Show Directories First")->addDep(sortSett->find("Always sort dirs by name"));
443 
444     panelGrid->addWidget(sortSett, 6, 0, 1, 2);
445 
446 
447     // ----------------------------------------------------------------------------------
448     //  ---------------------------- View modes -----------------------------------------
449     // ----------------------------------------------------------------------------------
450 
451     panelGrp = createFrame(i18n("View modes"), tab_panel);
452     panelLayout->addWidget(panelGrp, 1, 0);
453     panelGrid = createGridLayout(panelGrp);
454 
455     // -------------------- Default Panel Type ----------------------------------
456     hbox = new QHBoxLayout();
457 
458     hbox->addWidget(new QLabel(i18n("Default view mode:"), panelGrp));
459 
460     QList<KrViewInstance *> views = KrViewFactory::registeredViews();
461     const int viewsSize = views.size();
462     KONFIGURATOR_NAME_VALUE_PAIR *panelTypes = new KONFIGURATOR_NAME_VALUE_PAIR[ viewsSize ];
463 
464     QString defType = QString('0');
465 
466     for (int i = 0; i != viewsSize; i++) {
467         KrViewInstance * inst = views[ i ];
468         panelTypes[ i ].text = inst->description();
469         panelTypes[ i ].text.remove('&');
470         panelTypes[ i ].value = QString("%1").arg(inst->id());
471         if (inst->id() == KrViewFactory::defaultViewId())
472             defType = QString("%1").arg(inst->id());
473     }
474 
475     cmb = createComboBox("Look&Feel", "Default Panel Type", defType, panelTypes, viewsSize, panelGrp, false, false, PAGE_VIEW);
476     hbox->addWidget(cmb);
477     hbox->addWidget(createSpacer(panelGrp));
478 
479     delete [] panelTypes;
480 
481     panelGrid->addLayout(hbox, 0, 0);
482 
483     // ----- Individual Settings Per View Type ------------------------
484     QTabWidget *tabs_view = new QTabWidget(panelGrp);
485     panelGrid->addWidget(tabs_view, 11, 0);
486 
487     for(int i = 0; i < views.count(); i++) {
488         QWidget *tab = new QWidget(tabs_view);
489         tabs_view->addTab(tab, views[i]->description());
490         setupView(views[i], tab);
491     }
492 }
493 
494 // -----------------------------------------------------------------------------------
495 //  -------------------------- Panel Toolbar TAB ----------------------------------
496 // -----------------------------------------------------------------------------------
setupButtonsTab()497 void KgPanel::setupButtonsTab()
498 {
499     QScrollArea *scrollArea = new QScrollArea(tabWidget);
500     QWidget *tab = new QWidget(scrollArea);
501     scrollArea->setFrameStyle(QFrame::NoFrame);
502     scrollArea->setWidget(tab);
503     scrollArea->setWidgetResizable(true);
504     tabWidget->addTab(scrollArea, i18n("Buttons"));
505 
506     QBoxLayout * tabLayout = new QVBoxLayout(tab);
507     tabLayout->setSpacing(6);
508     tabLayout->setContentsMargins(11, 11, 11, 11);
509 
510     KONFIGURATOR_CHECKBOX_PARAM buttonsParams[] =
511         //   cfg_class    cfg_name                default        text                          restart tooltip
512     {
513         {"ListPanelButtons", "Icons", false, i18n("Toolbar buttons have icons"), true,   "" },
514         {"Look&Feel",  "Media Button Visible",  true,    i18n("Show Media Button"), true ,  i18n("The media button will be visible.") },
515         {"Look&Feel",  "Back Button Visible",  false,      i18n("Show Back Button"),     true ,  "Goes back in history." },
516         {"Look&Feel",  "Forward Button Visible",  false,   i18n("Show Forward Button"),     true ,  "Goes forward in history." },
517         {"Look&Feel",  "History Button Visible",  true,    i18n("Show History Button"), true ,  i18n("The history button will be visible.") },
518         {"Look&Feel",  "Bookmarks Button Visible",  true,    i18n("Show Bookmarks Button"), true ,  i18n("The bookmarks button will be visible.") },
519         {"Look&Feel", "Panel Toolbar visible", _PanelToolBar, i18n("Show Panel Toolbar"), true,   i18n("The panel toolbar will be visible.") },
520     };
521     buttonsCheckboxes = createCheckBoxGroup(1, 0, buttonsParams, 7/*count*/, tab, PAGE_PANELTOOLBAR);
522     connect(buttonsCheckboxes->find("Panel Toolbar visible"), SIGNAL(stateChanged(int)), this, SLOT(slotEnablePanelToolbar()));
523     tabLayout->addWidget(buttonsCheckboxes, 0, 0);
524 
525     QGroupBox * panelToolbarGrp = createFrame(i18n("Visible Panel Toolbar buttons"), tab);
526     QGridLayout * panelToolbarGrid = createGridLayout(panelToolbarGrp);
527     KONFIGURATOR_CHECKBOX_PARAM panelToolbarButtonsParams[] = {
528         //   cfg_class    cfg_name                default             text                       restart tooltip
529         {"Look&Feel",  "Equal Button Visible", _cdOther,   i18n("Equal button (=)"), true ,  i18n("Changes the panel folder to the other panel folder.") },
530         {"Look&Feel",  "Up Button Visible",    _cdUp,      i18n("Up button (..)"),  true ,  i18n("Changes the panel folder to the parent folder.") },
531         {"Look&Feel",  "Home Button Visible",  _cdHome,    i18n("Home button (~)"), true ,  i18n("Changes the panel folder to the home folder.") },
532         {"Look&Feel",  "Root Button Visible",  _cdRoot,    i18n("Root button (/)"), true ,  i18n("Changes the panel folder to the root folder.") },
533         {"Look&Feel",  "SyncBrowse Button Visible",  _syncBrowseButton,    i18n("Toggle-button for sync-browsing"), true ,  i18n("Each folder change in the panel is also performed in the other panel.") },
534     };
535     panelToolbarButtonsCheckboxes = createCheckBoxGroup(1, 0, panelToolbarButtonsParams,
536                                  sizeof(panelToolbarButtonsParams) / sizeof(*panelToolbarButtonsParams),
537                                  panelToolbarGrp, PAGE_PANELTOOLBAR);
538     panelToolbarGrid->addWidget(panelToolbarButtonsCheckboxes, 0, 0);
539     tabLayout->addWidget(panelToolbarGrp, 1, 0);
540 
541     // Enable panel toolbar checkboxes
542     slotEnablePanelToolbar();
543 }
544 
545 // ---------------------------------------------------------------------------
546 //  -------------------------- Mouse TAB ----------------------------------
547 // ---------------------------------------------------------------------------
setupMouseModeTab()548 void KgPanel::setupMouseModeTab()
549 {
550     QScrollArea *scrollArea = new QScrollArea(tabWidget);
551     QWidget *tab_mouse = new QWidget(scrollArea);
552     scrollArea->setFrameStyle(QFrame::NoFrame);
553     scrollArea->setWidget(tab_mouse);
554     scrollArea->setWidgetResizable(true);
555     tabWidget->addTab(scrollArea, i18n("Selection Mode"));
556     QGridLayout *mouseLayout = new QGridLayout(tab_mouse);
557     mouseLayout->setSpacing(6);
558     mouseLayout->setContentsMargins(11, 11, 11, 11);
559 
560     // -------------- General -----------------
561     QGroupBox *mouseGeneralGroup = createFrame(i18n("General"), tab_mouse);
562     QGridLayout *mouseGeneralGrid = createGridLayout(mouseGeneralGroup);
563     mouseGeneralGrid->setSpacing(0);
564     mouseGeneralGrid->setContentsMargins(5, 5, 5, 5);
565 
566     KONFIGURATOR_NAME_VALUE_TIP mouseSelection[] = {
567         //     name           value          tooltip
568         { i18n("Krusader Mode"), "0", i18n("Both keys allow selecting files. To select more than one file, hold the Ctrl key and click the left mouse button. Right-click menu is invoked using a short click on the right mouse button.") },
569         { i18n("Konqueror Mode"), "1", i18n("Pressing the left mouse button selects files - you can click and select multiple files. Right-click menu is invoked using a short click on the right mouse button.") },
570         { i18n("Total-Commander Mode"), "2", i18n("The left mouse button does not select, but sets the current file without affecting the current selection. The right mouse button selects multiple files and the right-click menu is invoked by pressing and holding the right mouse button.") },
571         { i18n("Ergonomic Mode"), "4", i18n("The left mouse button does not select, but sets the current file without affecting the current selection. The right mouse button invokes the context-menu. You can select with Ctrl key and the left button.") },
572         { i18n("Custom Selection Mode"), "3", i18n("Design your own selection mode.") }
573     };
574     mouseRadio = createRadioButtonGroup("Look&Feel", "Mouse Selection", "0", 1, 5, mouseSelection, 5, mouseGeneralGroup, true, PAGE_MOUSE);
575     mouseRadio->layout()->setContentsMargins(0, 0, 0, 0);
576     mouseGeneralGrid->addWidget(mouseRadio, 0, 0);
577 
578     for (int i = 0; i != mouseRadio->count(); i++)
579         connect(mouseRadio->find(i), SIGNAL(clicked()), SLOT(slotSelectionModeChanged()));
580 
581     mouseLayout->addWidget(mouseGeneralGroup, 0, 0);
582 
583     // -------------- Details -----------------
584     QGroupBox *mouseDetailGroup = createFrame(i18n("Details"), tab_mouse);
585     QGridLayout *mouseDetailGrid = createGridLayout(mouseDetailGroup);
586     mouseDetailGrid->setSpacing(0);
587     mouseDetailGrid->setContentsMargins(5, 5, 5, 5);
588 
589     KONFIGURATOR_NAME_VALUE_TIP singleOrDoubleClick[] = {
590         //          name            value            tooltip
591         { i18n("Double-click selects (classic)"), "0", i18n("A single click on a file will select and focus, a double click opens the file or steps into the folder.") },
592         { i18n("Obey global selection policy"), "1", i18n("<p>Use global setting:</p><p><i>Plasma System Settings -> Input Devices -> Mouse</i></p>") }
593     };
594     KonfiguratorRadioButtons *clickRadio = createRadioButtonGroup("Look&Feel", "Single Click Selects", "0", 1, 0, singleOrDoubleClick, 2, mouseDetailGroup, true, PAGE_MOUSE);
595     clickRadio->layout()->setContentsMargins(0, 0, 0, 0);
596     mouseDetailGrid->addWidget(clickRadio, 0, 0);
597 
598     KONFIGURATOR_CHECKBOX_PARAM mouseCheckboxesParam[] = {
599         // {cfg_class,   cfg_name,   default
600         //  text,  restart,
601         //  tooltip }
602         {"Custom Selection Mode",  "QT Selection",  _QtSelection,
603             i18n("Based on KDE's selection mode"), true,
604             i18n("If checked, use a mode based on KDE's style.") },
605         {"Custom Selection Mode",  "Left Selects",  _LeftSelects,
606          i18n("Left mouse button selects"), true,
607          i18n("If checked, left clicking an item will select it.") },
608         {"Custom Selection Mode",  "Left Preserves", _LeftPreserves,
609          i18n("Left mouse button preserves selection"), true,
610          i18n("If checked, left clicking an item will select it, but will not unselect other, already selected items.") },
611         {"Custom Selection Mode",  "ShiftCtrl Left Selects",  _ShiftCtrlLeft,
612          i18n("Shift/Ctrl-Left mouse button selects"), true,
613          i18n("If checked, Shift/Ctrl left clicking will select items.\nNote: this is meaningless if 'Left Button Selects' is checked.") },
614         {"Custom Selection Mode",  "Right Selects",  _RightSelects,
615          i18n("Right mouse button selects"), true,
616          i18n("If checked, right clicking an item will select it.") },
617         {"Custom Selection Mode",  "Right Preserves",  _RightPreserves,
618          i18n("Right mouse button preserves selection"), true,
619          i18n("If checked, right clicking an item will select it, but will not unselect other, already selected items.") },
620         {"Custom Selection Mode",  "ShiftCtrl Right Selects",  _ShiftCtrlRight,
621          i18n("Shift/Ctrl-Right mouse button selects"), true,
622          i18n("If checked, Shift/Ctrl right clicking will select items.\nNote: this is meaningless if 'Right Button Selects' is checked.") },
623         {"Custom Selection Mode",  "Space Moves Down",  _SpaceMovesDown,
624          i18n("Spacebar moves down"), true,
625          i18n("If checked, pressing the spacebar will select the current item and move down.\nOtherwise, current item is selected, but remains the current item.") },
626         {"Custom Selection Mode",  "Space Calc Space",  _SpaceCalcSpace,
627          i18n("Spacebar calculates disk space"), true,
628          i18n("If checked, pressing the spacebar while the current item is a folder, will (except from selecting the folder)\ncalculate space occupied of the folder (recursively).") },
629         {"Custom Selection Mode",  "Insert Moves Down",  _InsertMovesDown,
630          i18n("Insert moves down"), true,
631          i18n("If checked, pressing Insert will select the current item, and move down to the next item.\nOtherwise, current item is not changed.") },
632         {"Custom Selection Mode",  "Immediate Context Menu",  _ImmediateContextMenu,
633          i18n("Right clicking pops context menu immediately"), true,
634          i18n("If checked, right clicking will result in an immediate showing of the context menu.\nOtherwise, user needs to click and hold the right mouse button for 500ms.") },
635     };
636 
637 
638     mouseCheckboxes = createCheckBoxGroup(1, 0, mouseCheckboxesParam, 11 /*count*/, mouseDetailGroup, PAGE_MOUSE);
639     mouseDetailGrid->addWidget(mouseCheckboxes, 1, 0);
640 
641     for (int i = 0; i < mouseCheckboxes->count(); i++)
642         connect(mouseCheckboxes->find(i), SIGNAL(clicked()), SLOT(slotMouseCheckBoxChanged()));
643 
644     mouseLayout->addWidget(mouseDetailGroup, 0, 1, 2, 1);
645 
646     // Disable the details-button if not in custom-mode
647     slotSelectionModeChanged();
648 
649     // -------------- Preview -----------------
650     QGroupBox *mousePreviewGroup = createFrame(i18n("Preview"), tab_mouse);
651     QGridLayout *mousePreviewGrid = createGridLayout(mousePreviewGroup);
652     // TODO preview
653     mousePreview = new KrTreeWidget(mousePreviewGroup);
654     mousePreviewGrid->addWidget(mousePreview, 0 , 0);
655     mousePreviewGroup->setEnabled(false); // TODO re-enable once the preview is implemented
656     // ------------------------------------------
657     mouseLayout->addWidget(mousePreviewGroup, 1, 0);
658 }
659 
660 // ---------------------------------------------------------------------------
661 //  -------------------------- Media Menu TAB ----------------------------------
662 // ---------------------------------------------------------------------------
setupMediaMenuTab()663 void KgPanel::setupMediaMenuTab()
664 {
665     QScrollArea *scrollArea = new QScrollArea(tabWidget);
666     QWidget *tab = new QWidget(scrollArea);
667     scrollArea->setFrameStyle(QFrame::NoFrame);
668     scrollArea->setWidget(tab);
669     scrollArea->setWidgetResizable(true);
670     tabWidget->addTab(scrollArea, i18n("Media Menu"));
671 
672     QBoxLayout * tabLayout = new QVBoxLayout(tab);
673     tabLayout->setSpacing(6);
674     tabLayout->setContentsMargins(11, 11, 11, 11);
675 
676 
677     KONFIGURATOR_CHECKBOX_PARAM mediaMenuParams[] = {
678         //   cfg_class    cfg_name    default    text   restart tooltip
679         {"MediaMenu", "ShowPath",   true, i18n("Show Mount Path"),       false, 0 },
680         {"MediaMenu", "ShowFSType", true, i18n("Show File System Type"), false, 0 },
681     };
682     KonfiguratorCheckBoxGroup *mediaMenuCheckBoxes =
683         createCheckBoxGroup(1, 0, mediaMenuParams,
684                             sizeof(mediaMenuParams) / sizeof(*mediaMenuParams),
685                             tab, PAGE_MEDIA_MENU);
686     tabLayout->addWidget(mediaMenuCheckBoxes, 0, 0);
687 
688     QHBoxLayout *showSizeHBox = new QHBoxLayout();
689     showSizeHBox->addWidget(new QLabel(i18n("Show Size:"), tab));
690     KONFIGURATOR_NAME_VALUE_PAIR showSizeValues[] = {
691         { i18nc("setting 'show size'", "Always"), "Always" },
692         { i18nc("setting 'show size'", "When Device has no Label"), "WhenNoLabel" },
693         { i18nc("setting 'show size'", "Never"), "Never" },
694     };
695     KonfiguratorComboBox *showSizeCmb =
696         createComboBox("MediaMenu", "ShowSize",
697                        "Always", showSizeValues,
698                        sizeof(showSizeValues) / sizeof(*showSizeValues),
699                        tab, false, false, PAGE_MEDIA_MENU);
700     showSizeHBox->addWidget(showSizeCmb);
701     showSizeHBox->addStretch();
702     tabLayout->addLayout(showSizeHBox);
703 
704     tabLayout->addStretch();
705 }
706 
slotEnablePanelToolbar()707 void KgPanel::slotEnablePanelToolbar()
708 {
709     bool enableTB = buttonsCheckboxes->find("Panel Toolbar visible")->isChecked();
710     panelToolbarButtonsCheckboxes->find("Root Button Visible")->setEnabled(enableTB);
711     panelToolbarButtonsCheckboxes->find("Home Button Visible")->setEnabled(enableTB);
712     panelToolbarButtonsCheckboxes->find("Up Button Visible")->setEnabled(enableTB);
713     panelToolbarButtonsCheckboxes->find("Equal Button Visible")->setEnabled(enableTB);
714     panelToolbarButtonsCheckboxes->find("SyncBrowse Button Visible")->setEnabled(enableTB);
715 }
716 
slotSelectionModeChanged()717 void KgPanel::slotSelectionModeChanged()
718 {
719     KrSelectionMode *selectionMode =
720         KrSelectionMode::getSelectionHandlerForMode(mouseRadio->selectedValue());
721     if (selectionMode == NULL)   //User mode
722         return;
723     selectionMode->init();
724     mouseCheckboxes->find("QT Selection")->setChecked(selectionMode->useQTSelection());
725     mouseCheckboxes->find("Left Selects")->setChecked(selectionMode->leftButtonSelects());
726     mouseCheckboxes->find("Left Preserves")->setChecked(selectionMode->leftButtonPreservesSelection());
727     mouseCheckboxes->find("ShiftCtrl Left Selects")->setChecked(selectionMode->shiftCtrlLeftButtonSelects());
728     mouseCheckboxes->find("Right Selects")->setChecked(selectionMode->rightButtonSelects());
729     mouseCheckboxes->find("Right Preserves")->setChecked(selectionMode->rightButtonPreservesSelection());
730     mouseCheckboxes->find("ShiftCtrl Right Selects")->setChecked(selectionMode->shiftCtrlRightButtonSelects());
731     mouseCheckboxes->find("Space Moves Down")->setChecked(selectionMode->spaceMovesDown());
732     mouseCheckboxes->find("Space Calc Space")->setChecked(selectionMode->spaceCalculatesDiskSpace());
733     mouseCheckboxes->find("Insert Moves Down")->setChecked(selectionMode->insertMovesDown());
734     mouseCheckboxes->find("Immediate Context Menu")->setChecked(selectionMode->showContextMenu() == -1);
735 }
736 
slotMouseCheckBoxChanged()737 void KgPanel::slotMouseCheckBoxChanged()
738 {
739     mouseRadio->selectButton("3");    //custom selection mode
740 }
741 
activeSubPage()742 int KgPanel::activeSubPage()
743 {
744     return tabWidget->currentIndex();
745 }
746