File indexing completed on 2024-09-15 04:30:16
0001 /* 0002 * Bookmark editor 0003 * 0004 * SPDX-FileCopyrightText: 2023 Alexander Reinholdt <alexander.reinholdt@kdemail.net> 0005 * SPDX-License-Identifier: GPL-2.0-or-later 0006 */ 0007 0008 // application specific includes 0009 #include "smb4kbookmarkeditor.h" 0010 #include "core/smb4kbookmarkhandler.h" 0011 #include "core/smb4ksettings.h" 0012 0013 // Qt includes 0014 #include <QDialogButtonBox> 0015 #include <QMap> 0016 #include <QPushButton> 0017 #include <QVBoxLayout> 0018 #include <QWindow> 0019 0020 // KDE includes 0021 #include <KConfigGroup> 0022 #include <KLocalizedString> 0023 #include <KPluginFactory> 0024 #include <KWindowConfig> 0025 0026 Smb4KBookmarkEditor::Smb4KBookmarkEditor(QWidget *parent) 0027 : QDialog(parent) 0028 { 0029 setWindowTitle(i18n("Bookmark Editor")); 0030 setAttribute(Qt::WA_DeleteOnClose, true); 0031 0032 QVBoxLayout *layout = new QVBoxLayout(this); 0033 0034 m_mainWidget = new Smb4KConfigPageBookmarks(this); 0035 0036 connect(m_mainWidget, &Smb4KConfigPageBookmarks::bookmarksModified, this, &Smb4KBookmarkEditor::slotEnabledButtons); 0037 0038 layout->addWidget(m_mainWidget); 0039 0040 QDialogButtonBox *buttonBox = new QDialogButtonBox(this); 0041 m_saveButton = buttonBox->addButton(QDialogButtonBox::Save); 0042 m_saveButton->setEnabled(false); 0043 m_saveButton->setShortcut(QKeySequence::Save); 0044 m_cancelButton = buttonBox->addButton(QDialogButtonBox::Cancel); 0045 m_cancelButton->setShortcut(QKeySequence::Cancel); 0046 0047 connect(m_saveButton, &QPushButton::clicked, this, &Smb4KBookmarkEditor::slotSaveBookmarks); 0048 connect(m_cancelButton, &QPushButton::clicked, this, &Smb4KBookmarkEditor::reject); 0049 0050 layout->addWidget(buttonBox); 0051 0052 setMinimumWidth(sizeHint().width() > 350 ? sizeHint().width() : 350); 0053 0054 create(); 0055 0056 KConfigGroup dialogGroup(Smb4KSettings::self()->config(), QStringLiteral("BookmarkEditor")); 0057 QSize dialogSize; 0058 0059 if (dialogGroup.exists()) { 0060 KWindowConfig::restoreWindowSize(windowHandle(), dialogGroup); 0061 dialogSize = windowHandle()->size(); 0062 } else { 0063 dialogSize = sizeHint(); 0064 } 0065 0066 resize(dialogSize); // workaround for QTBUG-40584 0067 0068 KConfigGroup completionGroup(Smb4KSettings::self()->config(), QStringLiteral("CompletionItems")); 0069 0070 if (completionGroup.exists()) { 0071 QMap<QString, QStringList> completionItems; 0072 completionItems[QStringLiteral("CategoryCompletion")] = completionGroup.readEntry("CategoryCompletion", Smb4KBookmarkHandler::self()->categoryList()); 0073 completionItems[QStringLiteral("LabelCompletion")] = completionGroup.readEntry("LabelCompletion", QStringList()); 0074 completionItems[QStringLiteral("IpAddressCompletion")] = completionGroup.readEntry("IpAddressCompletion", QStringList()); 0075 completionItems[QStringLiteral("LoginCompletion")] = completionGroup.readEntry("LoginCompletion", QStringList()); 0076 completionItems[QStringLiteral("WorkgroupCompletion")] = completionGroup.readEntry("WorkgroupCompletion", QStringList()); 0077 0078 m_mainWidget->setCompletionItems(completionItems); 0079 } 0080 } 0081 0082 Smb4KBookmarkEditor::~Smb4KBookmarkEditor() 0083 { 0084 } 0085 0086 void Smb4KBookmarkEditor::slotEnabledButtons() 0087 { 0088 m_saveButton->setEnabled(m_mainWidget->bookmarksChanged()); 0089 } 0090 0091 void Smb4KBookmarkEditor::slotSaveBookmarks() 0092 { 0093 m_mainWidget->saveBookmarks(); 0094 0095 KConfigGroup dialogGroup(Smb4KSettings::self()->config(), QStringLiteral("BookmarkEditor")); 0096 KWindowConfig::saveWindowSize(windowHandle(), dialogGroup); 0097 0098 KConfigGroup completionGroup(Smb4KSettings::self()->config(), QStringLiteral("CompletionItems")); 0099 QMap<QString, QStringList> completionItems = m_mainWidget->completionItems(); 0100 0101 completionGroup.writeEntry("CategoryCompletion", completionItems[QStringLiteral("CategoryCompletion")]); 0102 completionGroup.writeEntry("LabelCompletion", completionItems[QStringLiteral("LabelCompletion")]); 0103 completionGroup.writeEntry("IpAddressCompletion", completionItems[QStringLiteral("IpAddressCompletion")]); 0104 completionGroup.writeEntry("LoginCompletion", completionItems[QStringLiteral("LoginCompletion")]); 0105 completionGroup.writeEntry("WorkgroupCompletion", completionItems[QStringLiteral("WorkgroupCompletion")]); 0106 0107 accept(); 0108 }