ConfigGeneral.qml 8.38 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
/***************************************************************************
 *   Copyright (C) 2014 by Eike Hein <hein@kde.org>                        *
 *                                                                         *
 *   This program is free software; you can redistribute it and/or modify  *
 *   it under the terms of the GNU General Public License as published by  *
 *   the Free Software Foundation; either version 2 of the License, or     *
 *   (at your option) any later version.                                   *
 *                                                                         *
 *   This program is distributed in the hope that it will be useful,       *
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
 *   GNU General Public License for more details.                          *
 *                                                                         *
 *   You should have received a copy of the GNU General Public License     *
 *   along with this program; if not, write to the                         *
 *   Free Software Foundation, Inc.,                                       *
 *   51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA .        *
 ***************************************************************************/

20 21
import QtQuick 2.5
import QtQuick.Controls 2.5
22

23 24
import org.kde.plasma.core 2.0 as PlasmaCore
import org.kde.kquickcontrolsaddons 2.0 as KQuickAddons
25
import org.kde.draganddrop 2.0 as DragDrop
26
import org.kde.kirigami 2.5 as Kirigami
27

28 29
import org.kde.plasma.private.kicker 0.1 as Kicker

30
Kirigami.FormLayout {
31 32
    id: configGeneral

33 34
    anchors.left: parent.left
    anchors.right: parent.right
35

Laurent Montel's avatar
Laurent Montel committed
36
    property bool isDash: (plasmoid.pluginName === "org.kde.plasma.kickerdash")
37

38 39 40
    property string cfg_icon: plasmoid.configuration.icon
    property bool cfg_useCustomButtonImage: plasmoid.configuration.useCustomButtonImage
    property string cfg_customButtonImage: plasmoid.configuration.customButtonImage
41

Eike Hein's avatar
Eike Hein committed
42
    property alias cfg_appNameFormat: appNameFormat.currentIndex
43
    property alias cfg_limitDepth: limitDepth.checked
44
    property alias cfg_alphaSort: alphaSort.checked
45
    property alias cfg_showIconsRootLevel: showIconsRootLevel.checked
46

47
    property alias cfg_recentOrdering: recentOrdering.currentIndex
48 49 50 51
    property alias cfg_showRecentApps: showRecentApps.checked
    property alias cfg_showRecentDocs: showRecentDocs.checked
    property alias cfg_showRecentContacts: showRecentContacts.checked

52 53 54 55
    property alias cfg_useExtraRunners: useExtraRunners.checked
    property alias cfg_alignResultsToBottom: alignResultsToBottom.checked


56 57
    Button {
        id: iconButton
58

59
        Kirigami.FormData.label: i18n("Icon:")
60

61 62
        implicitWidth: previewFrame.width + PlasmaCore.Units.smallSpacing * 2
        implicitHeight: previewFrame.height + PlasmaCore.Units.smallSpacing * 2
63

64 65 66 67
        // Just to provide some visual feedback when dragging;
        // cannot have checked without checkable enabled
        checkable: true
        checked: dropArea.containsAcceptableDrag
68

69
        onPressed: iconMenu.opened ? iconMenu.close() : iconMenu.open()
70

71 72
        DragDrop.DropArea {
            id: dropArea
73

74
            property bool containsAcceptableDrag: false
75

76
            anchors.fill: parent
Eike Hein's avatar
Eike Hein committed
77

78 79 80
            onDragEnter: {
                // Cannot use string operations (e.g. indexOf()) on "url" basic type.
                var urlString = event.mimeData.url.toString();
81

82 83 84 85 86
                // This list is also hardcoded in KIconDialog.
                var extensions = [".png", ".xpm", ".svg", ".svgz"];
                containsAcceptableDrag = urlString.indexOf("file:///") === 0 && extensions.some(function (extension) {
                    return urlString.indexOf(extension) === urlString.length - extension.length; // "endsWith"
                });
Eike Hein's avatar
Eike Hein committed
87

88 89
                if (!containsAcceptableDrag) {
                    event.ignore();
90
                }
91 92 93 94 95 96 97
            }
            onDragLeave: containsAcceptableDrag = false

            onDrop: {
                if (containsAcceptableDrag) {
                    // Strip file:// prefix, we already verified in onDragEnter that we have only local URLs.
                    iconDialog.setCustomButtonImage(event.mimeData.url.toString().substr("file://".length));
Eike Hein's avatar
Eike Hein committed
98
                }
99
                containsAcceptableDrag = false;
100 101 102
            }
        }

103 104
        KQuickAddons.IconDialog {
            id: iconDialog
105

106
            function setCustomButtonImage(image) {
107 108
                configGeneral.cfg_customButtonImage = image || configGeneral.cfg_icon || "start-here-kde"
                configGeneral.cfg_useCustomButtonImage = true;
109
            }
110

111 112
            onIconNameChanged: setCustomButtonImage(iconName);
        }
Eike Hein's avatar
Eike Hein committed
113

114 115 116 117 118
        PlasmaCore.FrameSvgItem {
            id: previewFrame
            anchors.centerIn: parent
            imagePath: plasmoid.location === PlasmaCore.Types.Vertical || plasmoid.location === PlasmaCore.Types.Horizontal
                    ? "widgets/panel-background" : "widgets/background"
119 120
            width: PlasmaCore.Units.iconSizes.large + fixedMargins.left + fixedMargins.right
            height: PlasmaCore.Units.iconSizes.large + fixedMargins.top + fixedMargins.bottom
121 122 123

            PlasmaCore.IconItem {
                anchors.centerIn: parent
124
                width: PlasmaCore.Units.iconSizes.large
125
                height: width
126
                source: configGeneral.cfg_useCustomButtonImage ? configGeneral.cfg_customButtonImage : configGeneral.cfg_icon
127 128 129 130 131
            }
        }

        Menu {
            id: iconMenu
Eike Hein's avatar
Eike Hein committed
132

133 134
            // Appear below the button
            y: +parent.height
Eike Hein's avatar
Eike Hein committed
135

136
            onClosed: iconButton.checked = false;
Eike Hein's avatar
Eike Hein committed
137

138 139 140 141 142 143 144 145 146
            MenuItem {
                text: i18nc("@item:inmenu Open icon chooser dialog", "Choose...")
                icon.name: "document-open-folder"
                onClicked: iconDialog.open()
            }
            MenuItem {
                text: i18nc("@item:inmenu Reset icon to default", "Clear Icon")
                icon.name: "edit-clear"
                onClicked: {
147 148
                    configGeneral.cfg_icon = "start-here-kde"
                    configGeneral.cfg_useCustomButtonImage = false
149
                }
150 151 152
            }
        }
    }
Eike Hein's avatar
Eike Hein committed
153 154


155 156 157
    Item {
        Kirigami.FormData.isSection: true
    }
158

159 160
    ComboBox {
        id: appNameFormat
161

162
        Kirigami.FormData.label: i18n("Show applications as:")
163

164 165
        model: [i18n("Name only"), i18n("Description only"), i18n("Name (Description)"), i18n("Description (Name)")]
    }
166

167 168 169
    Item {
        Kirigami.FormData.isSection: true
    }
170

171 172
    CheckBox {
        id: alphaSort
173

174
        Kirigami.FormData.label: i18n("Behavior:")
175

176 177
        text: i18n("Sort applications alphabetically")
    }
178

179 180
    CheckBox {
        id: limitDepth
181

182
        visible: !isDash
183

184 185
        text: i18n("Flatten sub-menus to a single level")
    }
186

187 188 189
    CheckBox {
        id: showIconsRootLevel

190
        visible: !configGeneral.isDash
191 192 193

        text: i18n("Show icons on the root level of the menu")
    }
194

195 196 197
    Item {
        Kirigami.FormData.isSection: true
    }
198

199 200
    CheckBox {
        id: showRecentApps
201

202
        Kirigami.FormData.label: i18n("Show categories:")
203

204 205 206 207
        text: recentOrdering.currentIndex == 0
                ? i18n("Recent applications")
                : i18n("Often used applications")
    }
208

209 210
    CheckBox {
        id: showRecentDocs
211

212
        text: recentOrdering.currentIndex == 0
213 214
                ? i18n("Recent files")
                : i18n("Often used files")
215
    }
216

217 218
    CheckBox {
        id: showRecentContacts
219

220 221 222 223
        text: recentOrdering.currentIndex == 0
                ? i18n("Recent contacts")
                : i18n("Often used contacts")
    }
224

225 226
    ComboBox {
        id: recentOrdering
227

228 229 230
        Kirigami.FormData.label: i18n("Sort items in categories by:")
        model: [i18nc("@item:inlistbox Sort items in categories by [Recently used | Often used]", "Recently used"), i18nc("@item:inlistbox Sort items in categories by [Recently used | Ofetn used]", "Often used")]
    }
231

232 233 234
    Item {
        Kirigami.FormData.isSection: true
    }
Eike Hein's avatar
Eike Hein committed
235

236 237
    CheckBox {
        id: useExtraRunners
238

239 240 241 242 243 244 245 246
        Kirigami.FormData.label: i18n("Search:")

        text: i18n("Expand search to bookmarks, files and emails")
    }

    CheckBox {
        id: alignResultsToBottom

247
        visible: !configGeneral.isDash
248 249

        text: i18n("Align search results to bottom")
250 251
    }
}