Warning, /plasma/aura-browser/app/qml/BookmarkManager.qml is written in an unsupported language. File is not indexed.
0001 /* 0002 SPDX-FileCopyrightText: 2022 Aditya Mehra <aix.m@outlook.com> 0003 0004 SPDX-License-Identifier: GPL-2.0-or-later 0005 */ 0006 0007 import QtQuick 2.12 0008 import QtQuick.Window 2.12 0009 import QtWebEngine 1.7 0010 import QtQuick.Layouts 1.12 0011 import QtQuick.Controls 2.12 as Controls 0012 import QtQml.Models 2.12 0013 import QtQuick.LocalStorage 2.12 0014 import QtQuick.VirtualKeyboard 2.4 0015 import "code/BookmarkStorage.js" as BookmarkStorage 0016 import Aura 1.0 as Aura 0017 import "code/Utils.js" as Utils 0018 import Qt5Compat.GraphicalEffects 0019 import org.kde.kirigami as Kirigami 0020 0021 Controls.Popup { 0022 id: bookmarkPopupArea 0023 property bool editMode: false 0024 property alias model: delegateFilter.model 0025 property var genericModel 0026 property alias bookmarkStack: bookmarkManagerStackLayout.currentIndex 0027 property var preBookmarkName 0028 property var preBookmarkUrl 0029 width: parent.width / 2 0030 height: parent.height / 2 0031 x: (parent.width - width) / 2 0032 y: (parent.height - height) / 2 0033 dim: true 0034 0035 Controls.Overlay.modeless: Rectangle { 0036 color: Qt.rgba(Kirigami.Theme.backgroundColor.r, Kirigami.Theme.backgroundColor.g, Kirigami.Theme.backgroundColor.b, 0.77) 0037 } 0038 0039 background: Rectangle { 0040 Kirigami.Theme.colorSet: Kirigami.Theme.View 0041 color: Kirigami.Theme.backgroundColor 0042 border.color: "black" 0043 } 0044 0045 onPreBookmarkNameChanged: { 0046 nameFieldChild.text = preBookmarkName 0047 } 0048 onPreBookmarkUrlChanged: { 0049 urlFieldChild.text = preBookmarkUrl 0050 } 0051 0052 function deleteBookmarkByRowId(id){ 0053 BookmarkStorage.dbDeleteRow(id); 0054 genericModel.clear(); 0055 delegateFilter.model.clear(); 0056 BookmarkStorage.dbReadAll(); 0057 } 0058 0059 function playKeySounds(event){ 0060 switch (event.key) { 0061 case Qt.Key_Down: 0062 case Qt.Key_Right: 0063 case Qt.Key_Left: 0064 case Qt.Key_Up: 0065 case Qt.Key_Tab: 0066 case Qt.Key_Backtab: 0067 Aura.NavigationSoundEffects.playMovingSound(); 0068 break; 0069 default: 0070 break; 0071 } 0072 } 0073 0074 onOpened: { 0075 if(bookmarkStack == 0){ 0076 bookmarkSearchField.forceActiveFocus() 0077 } else { 0078 nameField.forceActiveFocus() 0079 } 0080 } 0081 0082 DelegateModel { 0083 id: delegateFilter 0084 delegate: Controls.ItemDelegate { 0085 contentItem: RowLayout { 0086 id: layout 0087 spacing: Kirigami.Units.largeSpacing 0088 Rectangle { 0089 Layout.preferredHeight: Kirigami.Units.iconSizes.smallMedium 0090 Layout.preferredWidth: Kirigami.Units.iconSizes.smallMedium 0091 color: model.rand_color; 0092 0093 Controls.Label { 0094 text: model.recent_name.substring(0,1); 0095 anchors.centerIn: parent 0096 color: Kirigami.Theme.textColor 0097 } 0098 } 0099 0100 Controls.Label { 0101 text: model.recent_name 0102 Layout.preferredWidth: parent.width / 2 0103 elide: Text.ElideRight 0104 color: Kirigami.Theme.textColor 0105 } 0106 0107 Controls.Label { 0108 text: model.recent_url 0109 Layout.alignment: Qt.AlignRight 0110 horizontalAlignment: Text.AlignLeft 0111 Layout.fillWidth: true 0112 color: Kirigami.Theme.textColor 0113 } 0114 } 0115 0116 onClicked: (mouse)=> { 0117 Aura.NavigationSoundEffects.playClickedSound() 0118 if(removeModeBox.checked){ 0119 deleteBookmarkByRowId(id); 0120 } else { 0121 createTab(recent_url); 0122 bookmarkPopupArea.close(); 0123 } 0124 } 0125 0126 Keys.onReturnPressed: (event)=> { 0127 Aura.NavigationSoundEffects.playClickedSound() 0128 if(removeModeBox.checked){ 0129 deleteBookmarkByRowId(id); 0130 } else { 0131 createTab(recent_url); 0132 bookmarkPopupArea.close(); 0133 } 0134 } 0135 } 0136 groups: [ 0137 DelegateModelGroup { 0138 name: "filterGroup"; includeByDefault: true 0139 } 0140 ] 0141 filterOnGroup: "filterGroup" 0142 0143 function applyFilter(){ 0144 var numberOfFiles = genericModel.count; 0145 for (var i = 0; i < numberOfFiles; i++){ 0146 var bookmarks = genericModel.get(i, "recent_name"); 0147 var bookmarkName = bookmarks.recent_name 0148 if (bookmarkName.indexOf(bookmarkSearchFieldChild.text) != -1){ 0149 items.addGroups(i, 1, "filterGroup");} 0150 else { 0151 items.removeGroups(i, 1, "filterGroup"); 0152 } 0153 } 0154 } 0155 } 0156 0157 StackLayout { 0158 id: bookmarkManagerStackLayout 0159 currentIndex: 0 0160 anchors.fill: parent 0161 anchors.margins: Kirigami.Units.largeSpacing 0162 0163 Item { 0164 width: parent.width 0165 height: parent.height 0166 0167 RowLayout { 0168 id: headerAreaBMLPg1 0169 anchors.top: parent.top 0170 anchors.left: parent.left 0171 anchors.right: parent.right 0172 0173 Kirigami.Heading { 0174 id: bookmarkMgrHeading 0175 level: 1 0176 text: i18n("Bookmarks Manager") 0177 color: Kirigami.Theme.textColor 0178 width: parent.width 0179 horizontalAlignment: Qt.AlignLeft 0180 Layout.alignment: Qt.AlignLeft 0181 } 0182 0183 Controls.Label { 0184 id: backbtnlabelHeading 0185 text: i18n("Press 'esc' or the [←] Back button to close") 0186 color: Kirigami.Theme.textColor 0187 Layout.alignment: Qt.AlignRight 0188 } 0189 } 0190 0191 Kirigami.Separator { 0192 id: headrSeptBml 0193 anchors.top: headerAreaBMLPg1.bottom 0194 width: parent.width 0195 height: 1 0196 } 0197 0198 ColumnLayout { 0199 anchors.top: headrSeptBml.bottom 0200 anchors.left: parent.left 0201 anchors.right: parent.right 0202 anchors.bottom: parent.bottom 0203 0204 RowLayout { 0205 Layout.fillWidth: true 0206 Layout.preferredHeight: Kirigami.Units.gridUnit * 4 0207 0208 Item { 0209 id: bookmarkSearchField 0210 Layout.fillWidth: true 0211 Layout.preferredHeight: Kirigami.Units.gridUnit * 3 0212 KeyNavigation.right: removeModeBox 0213 KeyNavigation.down: bookmarksManagerListView 0214 Keys.onEnterPressed: bookmarkSearchFieldChild.forceActiveFocus() 0215 0216 Controls.TextField { 0217 id: bookmarkSearchFieldChild 0218 anchors.fill: parent 0219 placeholderText: i18n("Search Bookmarks") 0220 color: Kirigami.Theme.textColor 0221 background: Rectangle { 0222 Kirigami.Theme.colorSet: Kirigami.Theme.View 0223 color: Kirigami.Theme.backgroundColor 0224 border.color: bookmarkSearchField.activeFocus ? Kirigami.Theme.hoverColor : Kirigami.Theme.disabledTextColor 0225 border.width: 1 0226 } 0227 onTextChanged: { 0228 delegateFilter.applyFilter() 0229 } 0230 onAccepted: { 0231 bookmarkSearchField.forceActiveFocus() 0232 } 0233 } 0234 0235 Keys.onReturnPressed: (event)=> { 0236 Aura.NavigationSoundEffects.playClickedSound() 0237 bookmarkSearchFieldChild.forceActiveFocus(); 0238 } 0239 0240 Keys.onPressed: (event)=> { 0241 playKeySounds(event) 0242 } 0243 } 0244 0245 Controls.CheckBox { 0246 id: removeModeBox 0247 checkable: true 0248 checked: false 0249 text: i18n("Remove Mode") 0250 KeyNavigation.right: addModeBox 0251 KeyNavigation.left: bookmarkSearchField 0252 KeyNavigation.down: bookmarksManagerListView 0253 Kirigami.Theme.inherit: false 0254 Kirigami.Theme.colorSet: Kirigami.Theme.View 0255 0256 Keys.onReturnPressed: (event)=> { 0257 checked = !checked 0258 } 0259 0260 Keys.onPressed: (event)=> { 0261 playKeySounds(event) 0262 } 0263 } 0264 0265 Controls.Button { 0266 id: addModeBox 0267 text: i18n("Add") 0268 palette.buttonText: Kirigami.Theme.textColor 0269 Layout.preferredWidth: Kirigami.Units.gridUnit * 6 0270 KeyNavigation.left: removeModeBox 0271 KeyNavigation.down: bookmarksManagerListView 0272 0273 background: Rectangle { 0274 color: addModeBox.activeFocus ? Kirigami.Theme.highlightColor : Qt.lighter(Kirigami.Theme.backgroundColor, 1.2) 0275 border.color: Kirigami.Theme.disabledTextColor 0276 radius: 20 0277 } 0278 0279 onClicked: { 0280 bookmarkManagerStackLayout.currentIndex = 1 0281 } 0282 Keys.onReturnPressed: (event)=> { 0283 bookmarkManagerStackLayout.currentIndex = 1 0284 } 0285 0286 Keys.onPressed: (event)=> { 0287 playKeySounds(event) 0288 } 0289 } 0290 } 0291 0292 ListView { 0293 id: bookmarksManagerListView 0294 Layout.fillWidth: true 0295 Layout.fillHeight: true 0296 model: delegateFilter 0297 clip: true 0298 keyNavigationEnabled: true 0299 KeyNavigation.up: bookmarkSearchField 0300 0301 Keys.onPressed: (event)=> { 0302 playKeySounds(event) 0303 } 0304 } 0305 } 0306 } 0307 0308 Item { 0309 id: addBookMarkLayout 0310 Layout.fillWidth: true 0311 Layout.fillHeight: true 0312 0313 onVisibleChanged: { 0314 if(visible){ 0315 nameField.forceActiveFocus() 0316 } 0317 } 0318 0319 RowLayout { 0320 id: headerAreaBML 0321 anchors.top: parent.top 0322 anchors.left: parent.left 0323 anchors.right: parent.right 0324 0325 Kirigami.Heading { 0326 id: bookmarkAddHeading 0327 level: 1 0328 text: i18n("Add Bookmark") 0329 color: Kirigami.Theme.textColor 0330 width: parent.width 0331 horizontalAlignment: Qt.AlignLeft 0332 Layout.alignment: Qt.AlignLeft 0333 } 0334 0335 Controls.Label { 0336 id: backbtnlabel 0337 text: i18n("Press 'esc' or the [←] Back button to close") 0338 color: Kirigami.Theme.textColor 0339 Layout.alignment: Qt.AlignRight 0340 } 0341 } 0342 0343 Kirigami.Separator { 0344 id: headrSept 0345 anchors.top: headerAreaBML.bottom 0346 width: parent.width 0347 height: 1 0348 } 0349 0350 RowLayout { 0351 id: nameRow 0352 anchors.top: headrSept.bottom 0353 anchors.left: parent.left 0354 anchors.right: parent.right 0355 height: Kirigami.Units.gridUnit * 4 0356 0357 Kirigami.Heading { 0358 level: 3 0359 text: i18n("Name: ") 0360 color: Kirigami.Theme.textColor 0361 Layout.preferredWidth: Kirigami.Units.gridUnit * 5 0362 Layout.alignment: Qt.AlignRight | Qt.AlignVCenter 0363 } 0364 0365 Item { 0366 id: nameField 0367 Layout.fillWidth: true 0368 Layout.preferredHeight: Kirigami.Units.gridUnit * 3 0369 KeyNavigation.down: urlField 0370 0371 Keys.onReturnPressed: { 0372 nameFieldChild.forceActiveFocus() 0373 } 0374 0375 Keys.onPressed: { 0376 playKeySounds(event) 0377 } 0378 0379 Controls.TextField { 0380 id: nameFieldChild 0381 anchors.fill: parent 0382 color: Kirigami.Theme.textColor 0383 background: Rectangle { 0384 Kirigami.Theme.colorSet: Kirigami.Theme.View 0385 color: Kirigami.Theme.backgroundColor 0386 border.color: nameField.activeFocus ? Kirigami.Theme.hoverColor : Kirigami.Theme.disabledTextColor 0387 border.width: 1 0388 } 0389 0390 Keys.onPressed: (event)=> { 0391 playKeySounds(event) 0392 } 0393 0394 onAccepted: { 0395 Aura.NavigationSoundEffects.playClickedSound() 0396 urlField.forceActiveFocus() 0397 } 0398 } 0399 } 0400 } 0401 0402 RowLayout { 0403 id: urlRow 0404 anchors.top: nameRow.bottom 0405 anchors.left: parent.left 0406 anchors.right: parent.right 0407 height: Kirigami.Units.gridUnit * 4 0408 0409 Kirigami.Heading { 0410 level: 3 0411 text: i18n("Url: ") 0412 color: Kirigami.Theme.textColor 0413 Layout.preferredWidth: Kirigami.Units.gridUnit * 5 0414 Layout.alignment: Qt.AlignRight | Qt.AlignVCenter 0415 } 0416 0417 Item { 0418 id: urlField 0419 Layout.fillWidth: true 0420 Layout.preferredHeight: Kirigami.Units.gridUnit * 3 0421 KeyNavigation.up: nameField 0422 KeyNavigation.down: catField 0423 0424 Keys.onReturnPressed: (event)=> { 0425 urlFieldChild.forceActiveFocus() 0426 } 0427 0428 Keys.onPressed: (event)=> { 0429 playKeySounds(event) 0430 } 0431 0432 Controls.TextField { 0433 id: urlFieldChild 0434 anchors.fill: parent 0435 color: Kirigami.Theme.textColor 0436 background: Rectangle { 0437 Kirigami.Theme.colorSet: Kirigami.Theme.View 0438 color: Kirigami.Theme.backgroundColor 0439 border.color: urlField.activeFocus ? Kirigami.Theme.hoverColor : Kirigami.Theme.disabledTextColor 0440 border.width: 1 0441 } 0442 0443 Keys.onPressed: (event)=> { 0444 playKeySounds(event) 0445 } 0446 0447 onAccepted: { 0448 Aura.NavigationSoundEffects.playClickedSound() 0449 catRow.forceActiveFocus() 0450 } 0451 } 0452 } 0453 } 0454 0455 RowLayout { 0456 id: catRow 0457 anchors.top: urlRow.bottom 0458 anchors.left: parent.left 0459 anchors.right: parent.right 0460 height: Kirigami.Units.gridUnit * 4 0461 Kirigami.Heading { 0462 level: 3 0463 text: i18n("Category: ") 0464 color: Kirigami.Theme.textColor 0465 Layout.preferredWidth: Kirigami.Units.gridUnit * 5 0466 Layout.alignment: Qt.AlignRight | Qt.AlignVCenter 0467 } 0468 0469 Item { 0470 id: catField 0471 Layout.fillWidth: true 0472 Layout.preferredHeight: Kirigami.Units.gridUnit * 3 0473 KeyNavigation.up: urlField 0474 KeyNavigation.down: addBookMarkBtn 0475 0476 Keys.onReturnPressed: (event)=> { 0477 catFieldChild.forceActiveFocus() 0478 } 0479 0480 Keys.onPressed: (event)=> { 0481 playKeySounds(event) 0482 } 0483 0484 Controls.ComboBox { 0485 id: catFieldChild 0486 model: ["News", "Entertainment", "Infotainment", "General"] 0487 currentIndex: 3 0488 anchors.fill: parent 0489 palette.buttonText: Kirigami.Theme.textColor 0490 0491 background: Rectangle { 0492 Kirigami.Theme.colorSet: Kirigami.Theme.View 0493 color: Kirigami.Theme.backgroundColor 0494 border.color: catField.activeFocus ? Kirigami.Theme.hoverColor : Kirigami.Theme.disabledTextColor 0495 border.width: 1 0496 } 0497 0498 Keys.onReturnPressed: (event)=> { 0499 addBookMarkBtn.forceActiveFocus() 0500 } 0501 0502 Keys.onPressed: (event)=> { 0503 playKeySounds(event) 0504 } 0505 } 0506 } 0507 } 0508 0509 RowLayout { 0510 id: addBookMarkBtnRow 0511 anchors.bottom: parent.bottom 0512 anchors.left: parent.left 0513 anchors.right: parent.right 0514 height: Kirigami.Units.gridUnit * 3 0515 0516 Controls.Button { 0517 id: backBookMarkBtn 0518 text: i18n("Bookmarks") 0519 Layout.fillWidth: true 0520 Layout.fillHeight: true 0521 KeyNavigation.right: addBookMarkBtn 0522 KeyNavigation.up: nameField 0523 palette.buttonText: Kirigami.Theme.textColor 0524 0525 background: Rectangle { 0526 color: backBookMarkBtn.activeFocus ? Kirigami.Theme.highlightColor : Qt.lighter(Kirigami.Theme.backgroundColor, 1.2) 0527 border.color: Kirigami.Theme.disabledTextColor 0528 radius: 2 0529 } 0530 onClicked: (mouse)=> { 0531 Aura.NavigationSoundEffects.playClickedSound() 0532 bookmarkManagerStackLayout.currentIndex = 0 0533 bookmarkSearchField.forceActiveFocus() 0534 } 0535 Keys.onReturnPressed: (event)=> { 0536 bookmarkManagerStackLayout.currentIndex = 0 0537 bookmarkSearchField.forceActiveFocus() 0538 } 0539 Keys.onPressed: (event)=> { 0540 playKeySounds(event) 0541 } 0542 } 0543 0544 Controls.Button { 0545 id: addBookMarkBtn 0546 text: i18n("Add") 0547 palette.buttonText: Kirigami.Theme.textColor 0548 0549 Layout.fillWidth: true 0550 Layout.fillHeight: true 0551 KeyNavigation.left: backBookMarkBtn 0552 KeyNavigation.up: nameField 0553 background: Rectangle { 0554 color: addBookMarkBtn.activeFocus ? Kirigami.Theme.highlightColor : Qt.lighter(Kirigami.Theme.backgroundColor, 1.2) 0555 border.color: Kirigami.Theme.disabledTextColor 0556 radius: 2 0557 } 0558 onClicked: (mouse)=> { 0559 Aura.NavigationSoundEffects.playClickedSound() 0560 Utils.insertBookmarkToManager(urlFieldChild.text, nameFieldChild.text, catFieldChild.currentText) 0561 bookmarkPopupArea.close() 0562 } 0563 Keys.onReturnPressed: (event)=> { 0564 Utils.insertBookmarkToManager(urlFieldChild.text, nameFieldChild.text, catFieldChild.currentText) 0565 bookmarkPopupArea.close() 0566 } 0567 Keys.onPressed: (event)=> { 0568 playKeySounds(event) 0569 } 0570 } 0571 } 0572 } 0573 } 0574 }