File indexing completed on 2024-04-28 17:06:09

0001 /*
0002     SPDX-FileCopyrightText: 2004 Csaba Karai <krusader@users.sourceforge.net>
0003     SPDX-FileCopyrightText: 2004-2022 Krusader Krew <https://krusader.org>
0004 
0005     SPDX-License-Identifier: GPL-2.0-or-later
0006 */
0007 
0008 #include "kgstartup.h"
0009 #include "../GUI/profilemanager.h"
0010 #include "../defaults.h"
0011 
0012 // QtWidgets
0013 #include <QGridLayout>
0014 #include <QLabel>
0015 
0016 #include <KCompletion/KLineEdit>
0017 #include <KI18n/KLocalizedString>
0018 
0019 KgStartup::KgStartup(bool first, QWidget *parent)
0020     : KonfiguratorPage(first, parent)
0021     , profileCombo(nullptr)
0022 {
0023     QWidget *innerWidget = new QFrame(this);
0024     setWidget(innerWidget);
0025     setWidgetResizable(true);
0026     auto *kgStartupLayout = new QGridLayout(innerWidget);
0027     kgStartupLayout->setSpacing(6);
0028 
0029     //  --------------------------- PANELS GROUPBOX ----------------------------------
0030 
0031     QGroupBox *panelsGrp = createFrame(i18n("General"), innerWidget);
0032     QGridLayout *panelsGrid = createGridLayout(panelsGrp);
0033 
0034     QString s = "<p><img src='toolbar|user-identity'></p>"
0035         + i18n("Defines the panel profile used at startup. A panel profile contains:<ul><li>all the tabs paths</li><li>the current tab</li><li>the active "
0036                "panel</li></ul><b>&lt;Last session&gt;</b> is a special panel profile which is saved automatically when Krusader is closed.");
0037     QLabel *label = addLabel(panelsGrid, 0, 0, i18n("Startup profile:"), panelsGrp);
0038     panelsGrp->setWhatsThis(s);
0039 
0040     QStringList profileList = ProfileManager::availableProfiles("Panel");
0041     profileList.push_front(i18n("<Last session>"));
0042 
0043     const int profileListSize = profileList.size();
0044     auto *comboItems = new KONFIGURATOR_NAME_VALUE_PAIR[profileListSize];
0045     for (int i = 0; i != profileListSize; i++)
0046         comboItems[i].text = comboItems[i].value = profileList[i];
0047     comboItems[0].value = "";
0048 
0049     profileCombo = createComboBox("Startup", "Starter Profile Name", comboItems[0].value, comboItems, profileListSize, label, panelsGrp, false, false);
0050     profileCombo->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed);
0051     panelsGrid->addWidget(profileCombo, 0, 1);
0052 
0053     delete[] comboItems;
0054 
0055     //------------------------------------------------
0056     panelsGrid->addWidget(createLine(panelsGrp), 1, 0, 1, 2);
0057 
0058     KONFIGURATOR_CHECKBOX_PARAM settings[] = {
0059         //   cfg_class  cfg_name                default             text                              restart tooltip
0060         {"Look&Feel", "Show splashscreen", _ShowSplashScreen, i18n("Show splashscreen"), false, i18n("Display a splashscreen when starting Krusader.")},
0061         {"Look&Feel", "Single Instance Mode", _SingleInstanceMode, i18n("Single instance mode"), false, i18n("Only one Krusader instance is allowed to run.")}};
0062 
0063     KonfiguratorCheckBoxGroup *cbs = createCheckBoxGroup(2, 0, settings, 2 /* settings count */, panelsGrp);
0064     panelsGrid->addWidget(cbs, 2, 0, 1, 2);
0065 
0066     auto *iconThemeLayout = new QHBoxLayout();
0067     QLabel *iconThemeLabel = new QLabel(i18n("Fallback Icon Theme:"));
0068     QString toolTip = i18n(
0069         "Whenever icon is not found in system icon theme, "
0070         "this theme will be used as a fallback. "
0071         "If fallback theme doesn't contain the icon, "
0072         "Breeze or Oxygen will be used if any of these are present.");
0073     iconThemeLayout->addWidget(iconThemeLabel);
0074     KonfiguratorEditBox *iconThemeEditBox = createEditBox("Startup", "Fallback Icon Theme", "", iconThemeLabel, panelsGrp, true, toolTip);
0075     iconThemeLayout->addWidget(iconThemeEditBox);
0076     iconThemeLayout->addStretch(1);
0077     panelsGrid->addLayout(iconThemeLayout, 3, 0, 1, 2);
0078 
0079     kgStartupLayout->addWidget(panelsGrp, 0, 0);
0080 
0081     //  ------------------------ USERINTERFACE GROUPBOX ------------------------------
0082 
0083     QGroupBox *uiGrp = createFrame(i18n("User Interface"), innerWidget);
0084     QGridLayout *uiGrid = createGridLayout(uiGrp);
0085 
0086     KONFIGURATOR_CHECKBOX_PARAM uiSettings[] = {
0087         // cfg_class cfg_name default text restart tooltip
0088         {"Startup",
0089          "Remember Position",
0090          _RememberPos,
0091          i18n("Save last position, size and panel settings"),
0092          false,
0093          i18n("<p>At startup, the main window will resize itself to the size it was when last shutdown. "
0094               "It will also appear in the same location of the screen, having panels sorted and aligned as they were before.</p> "
0095               "<p>If this option is disabled, you can use the menu <i>Window -> Save Position</i> option "
0096               "to manually set the main window's size and position at startup.</p>")},
0097         {"Startup",
0098          "Update Default Panel Settings",
0099          _RememberPos,
0100          i18n("Update default panel settings"),
0101          true,
0102          i18n("When settings of a panel are changed, save them as the default for new panels of the same type.")},
0103         {"Startup", "Start To Tray", _StartToTray, i18n("Start to tray"), false, i18n("Krusader starts to tray, without showing the main window")},
0104     };
0105 
0106     KonfiguratorCheckBoxGroup *uiSettingsGroup = createCheckBoxGroup(1, 0, uiSettings, 3, uiGrp);
0107     uiGrid->addWidget(uiSettingsGroup, 1, 0);
0108 
0109     KONFIGURATOR_CHECKBOX_PARAM uiCheckBoxes[] = {
0110         //   cfg_class, cfg_name, default, text, restart, ToolTip
0111         {"Startup",
0112          "UI Save Settings",
0113          _UiSave,
0114          i18n("Save component settings on exit"),
0115          false,
0116          i18n("Check the state of the user interface components and restore them to their condition when last shutdown.")},
0117         {"Startup", "Show FN Keys", _ShowFNkeys, i18n("Show function keys"), false, i18n("Function keys will be visible after startup.")},
0118         {"Startup", "Show Cmd Line", _ShowCmdline, i18n("Show command line"), false, i18n("Command line will be visible after startup.")},
0119         {"Startup",
0120          "Show Terminal Emulator",
0121          _ShowTerminalEmulator,
0122          i18n("Show embedded terminal"),
0123          false,
0124          i18n("Embedded terminal will be visible after startup.")},
0125     };
0126 
0127     uiCbGroup = createCheckBoxGroup(1, 0, uiCheckBoxes, 4, uiGrp);
0128     connect(uiCbGroup->find("UI Save Settings"), &KonfiguratorCheckBox::stateChanged, this, &KgStartup::slotDisable);
0129 
0130     uiGrid->addWidget(uiCbGroup, 2, 0);
0131 
0132     slotDisable();
0133 
0134     kgStartupLayout->addWidget(uiGrp, 1, 0);
0135 }
0136 
0137 void KgStartup::slotDisable()
0138 {
0139     bool isUiSave = !uiCbGroup->find("UI Save Settings")->isChecked();
0140 
0141     int i = 1;
0142     while (uiCbGroup->find(i))
0143         uiCbGroup->find(i++)->setEnabled(isUiSave);
0144 }