diff --git a/core/smb4kbookmarkhandler.cpp b/core/smb4kbookmarkhandler.cpp index dc5a198..796dda8 100644 --- a/core/smb4kbookmarkhandler.cpp +++ b/core/smb4kbookmarkhandler.cpp @@ -1,675 +1,672 @@ /*************************************************************************** This class handles the bookmarks. ------------------- begin : Fr Jan 9 2004 copyright : (C) 2004-2019 by Alexander Reinholdt email : alexander.reinholdt@kdemail.net ***************************************************************************/ /*************************************************************************** * 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, Suite 500, Boston,* * MA 02110-1335, USA * ***************************************************************************/ #ifdef HAVE_CONFIG_H #include #endif // application specific includes #include "smb4kbookmarkhandler.h" #include "smb4kbookmarkhandler_p.h" #include "smb4khomesshareshandler.h" #include "smb4kglobal.h" #include "smb4kbookmark.h" #include "smb4khost.h" #include "smb4kshare.h" #include "smb4ksettings.h" #include "smb4knotification.h" #include "smb4kprofilemanager.h" // Qt includes #include #include #include #include #include #include #include #include #include // KDE includes #define TRANSLATION_DOMAIN "smb4k-core" #include using namespace Smb4KGlobal; Q_GLOBAL_STATIC(Smb4KBookmarkHandlerStatic, p); Smb4KBookmarkHandler::Smb4KBookmarkHandler(QObject *parent) : QObject(parent), d(new Smb4KBookmarkHandlerPrivate) { // // First we need the directory. // QString path = dataLocation(); QDir dir; if (!dir.exists(path)) { dir.mkpath(path); } // // Read the list of bookmarks // readBookmarkList(); // // Init the bookmark editor // d->editor = 0; } Smb4KBookmarkHandler::~Smb4KBookmarkHandler() { while (!d->bookmarks.isEmpty()) { d->bookmarks.takeFirst().clear(); } } Smb4KBookmarkHandler *Smb4KBookmarkHandler::self() { return &p->instance; } void Smb4KBookmarkHandler::addBookmark(const SharePtr &share) { if (share) { QList shares; shares << share; addBookmarks(shares); } } void Smb4KBookmarkHandler::addBookmarks(const QList &list) { // // Prepare the list of bookmarks that should be added // QList newBookmarks; for (const SharePtr &share : list) { // // Printer shares cannot be bookmarked // if (share->isPrinter()) { Smb4KNotification::cannotBookmarkPrinter(share); continue; } // // Process homes shares // - if (share->isHomesShare()) + if (share->isHomesShare() && !Smb4KHomesSharesHandler::self()->specifyUser(share, true)) { - if (!Smb4KHomesSharesHandler::self()->specifyUser(share, true)) - { - continue; - } + continue; } // // Check if the share has already been bookmarked and skip it if it // already exists // BookmarkPtr knownBookmark = findBookmarkByUrl(share->isHomesShare() ? share->homeUrl() : share->url()); if (knownBookmark) { Smb4KNotification::bookmarkExists(knownBookmark.data()); continue; } BookmarkPtr bookmark = BookmarkPtr(new Smb4KBookmark(share.data())); bookmark->setProfile(Smb4KProfileManager::self()->activeProfile()); newBookmarks << bookmark; } // // Show the bookmark dialog, if necessary // if (!newBookmarks.isEmpty()) { QPointer dlg = new Smb4KBookmarkDialog(newBookmarks, groupsList(), QApplication::activeWindow()); if (dlg->exec() == QDialog::Accepted) { // The bookmark dialog uses an internal list of bookmarks, // so use that one instead of the temporary list created // above. addBookmarks(dlg->bookmarks(), false); } delete dlg; } // // Clear the temporary list of bookmarks // while (!newBookmarks.isEmpty()) { newBookmarks.takeFirst().clear(); } } void Smb4KBookmarkHandler::addBookmarks(const QList &list, bool replace) { // // Process the incoming list. // In case the internal list should be replaced, clear the internal // list first. // if (replace) { QMutableListIterator it(d->bookmarks); while (it.hasNext()) { BookmarkPtr bookmark = it.next(); if (Smb4KSettings::useProfiles() && bookmark->profile() != Smb4KProfileManager::self()->activeProfile()) { continue; } it.remove(); } } // // Copy all bookmarks that are not in the list // for (const BookmarkPtr &bookmark : list) { // // Check if the bookmark label is already in use // if (!bookmark->label().isEmpty() && findBookmarkByLabel(bookmark->label())) { Smb4KNotification::bookmarkLabelInUse(bookmark.data()); bookmark->setLabel(QString("%1 (1)").arg(bookmark->label())); } // // Check if we have to add the bookmark // BookmarkPtr existingBookmark = findBookmarkByUrl(bookmark->url()); if (!existingBookmark) { d->bookmarks << bookmark; } else { // We do not need to update the bookmark, because we are // operating on a shared pointer. } } // // Save the bookmark list and emit the updated() signal // writeBookmarkList(); emit updated(); } void Smb4KBookmarkHandler::removeBookmark(const BookmarkPtr &bookmark) { if (bookmark) { for (int i = 0; i < d->bookmarks.size(); ++i) { if ((!Smb4KSettings::useProfiles() || Smb4KSettings::activeProfile() == d->bookmarks.at(i)->profile()) && QString::compare(d->bookmarks.at(i)->url().toString(QUrl::RemoveUserInfo|QUrl::RemovePort), bookmark->url().toString(QUrl::RemoveUserInfo|QUrl::RemovePort), Qt::CaseInsensitive) == 0 && QString::compare(bookmark->groupName(), d->bookmarks.at(i)->groupName(), Qt::CaseInsensitive) == 0) { d->bookmarks.takeAt(i).clear(); break; } } // Write the list to the bookmarks file. writeBookmarkList(); emit updated(); } } void Smb4KBookmarkHandler::removeGroup(const QString& name) { QMutableListIterator it(d->bookmarks); while (it.hasNext()) { const BookmarkPtr &b = it.next(); if ((!Smb4KSettings::useProfiles() || Smb4KSettings::activeProfile() == b->profile()) || QString::compare(b->groupName(), name, Qt::CaseInsensitive) == 0) { it.remove(); } } // Write the list to the bookmarks file. writeBookmarkList(); emit updated(); } void Smb4KBookmarkHandler::writeBookmarkList() { QFile xmlFile(dataLocation()+QDir::separator()+"bookmarks.xml"); if (!d->bookmarks.isEmpty()) { if (xmlFile.open(QIODevice::WriteOnly|QIODevice::Text)) { QXmlStreamWriter xmlWriter(&xmlFile); xmlWriter.setAutoFormatting(true); xmlWriter.writeStartDocument(); xmlWriter.writeStartElement("bookmarks"); xmlWriter.writeAttribute("version", "2.0"); for (const BookmarkPtr &bookmark : d->bookmarks) { if (!bookmark->url().isValid()) { Smb4KNotification::invalidURLPassed(); continue; } xmlWriter.writeStartElement("bookmark"); xmlWriter.writeAttribute("profile", bookmark->profile()); xmlWriter.writeAttribute("group", bookmark->groupName()); xmlWriter.writeTextElement("workgroup", bookmark->workgroupName()); xmlWriter.writeTextElement("url", bookmark->url().toString(QUrl::RemoveUserInfo|QUrl::RemovePort)); xmlWriter.writeTextElement("login", bookmark->login()); xmlWriter.writeTextElement("ip", bookmark->hostIpAddress()); xmlWriter.writeTextElement("label", bookmark->label()); xmlWriter.writeEndElement(); } xmlWriter.writeEndDocument(); xmlFile.close(); } else { Smb4KNotification::openingFileFailed(xmlFile); } } else { xmlFile.remove(); } } void Smb4KBookmarkHandler::readBookmarkList() { // // Clear the list of bookmarks // while (!d->bookmarks.isEmpty()) { d->bookmarks.takeFirst().clear(); } // // Locate the XML file and read the bookmarks // QFile xmlFile(dataLocation()+QDir::separator()+"bookmarks.xml"); if (xmlFile.open(QIODevice::ReadOnly | QIODevice::Text)) { QXmlStreamReader xmlReader(&xmlFile); while (!xmlReader.atEnd()) { xmlReader.readNext(); if (xmlReader.isStartElement()) { if (xmlReader.name() == "bookmarks" && (xmlReader.attributes().value("version") != "1.1" && xmlReader.attributes().value("version") != "2.0")) { xmlReader.raiseError(i18n("The format of %1 is not supported.", xmlFile.fileName())); break; } else { if (xmlReader.name() == "bookmark") { QString profile = xmlReader.attributes().value("profile").toString(); BookmarkPtr bookmark = BookmarkPtr(new Smb4KBookmark()); bookmark->setProfile(profile); bookmark->setGroupName(xmlReader.attributes().value("group").toString()); while (!(xmlReader.isEndElement() && xmlReader.name() == "bookmark")) { xmlReader.readNext(); if (xmlReader.isStartElement()) { if (xmlReader.name() == "workgroup") { bookmark->setWorkgroupName(xmlReader.readElementText()); } else if (xmlReader.name() == "unc") { bookmark->setUrl(xmlReader.readElementText()); } else if (xmlReader.name() == "url") { bookmark->setUrl(QUrl(xmlReader.readElementText())); } else if (xmlReader.name() == "login") { bookmark->setLogin(xmlReader.readElementText()); } else if (xmlReader.name() == "ip") { bookmark->setHostIpAddress(xmlReader.readElementText()); } else if (xmlReader.name() == "label") { bookmark->setLabel(xmlReader.readElementText()); } continue; } else { continue; } } d->bookmarks << bookmark; } else { continue; } } } else { continue; } } xmlFile.close(); if (xmlReader.hasError()) { Smb4KNotification::readingFileFailed(xmlFile, xmlReader.errorString()); } } else { if (xmlFile.exists()) { Smb4KNotification::openingFileFailed(xmlFile); } } emit updated(); } BookmarkPtr Smb4KBookmarkHandler::findBookmarkByUrl(const QUrl &url) { // Update the bookmarks: update(); // Find the bookmark: BookmarkPtr bookmark; if (!url.isEmpty() && url.isValid() && !bookmarksList().isEmpty()) { for (const BookmarkPtr &b : bookmarksList()) { if (QString::compare(b->url().toString(QUrl::RemoveUserInfo|QUrl::RemovePort), url.toString(QUrl::RemoveUserInfo|QUrl::RemovePort), Qt::CaseInsensitive) == 0) { bookmark = b; break; } } } return bookmark; } BookmarkPtr Smb4KBookmarkHandler::findBookmarkByLabel(const QString &label) { // Update the bookmarks: update(); // Find the bookmark: BookmarkPtr bookmark; for (const BookmarkPtr &b : bookmarksList()) { if (QString::compare(b->label().toUpper(), label.toUpper()) == 0) { bookmark = b; break; } else { continue; } } return bookmark; } QList Smb4KBookmarkHandler::bookmarksList() const { // Update the bookmarks: update(); // Get this list of the bookmarks if (Smb4KSettings::useProfiles()) { QList bookmarks; for (const BookmarkPtr &b : d->bookmarks) { if (b->profile() == Smb4KSettings::activeProfile()) { bookmarks << b; } } return bookmarks; } // Return the list of bookmarks: return d->bookmarks; } QList Smb4KBookmarkHandler::bookmarksList(const QString &group) const { // Update bookmarks update(); // Get the list of bookmarks organized in the given group QList bookmarks; for (const BookmarkPtr &bookmark : bookmarksList()) { if (QString::compare(group, bookmark->groupName(), Qt::CaseInsensitive) == 0) { bookmarks << bookmark; } } return bookmarks; } QStringList Smb4KBookmarkHandler::groupsList() const { QStringList groups; for (const BookmarkPtr &b : bookmarksList()) { if (!groups.contains(b->groupName())) { groups << b->groupName(); } } return groups; } void Smb4KBookmarkHandler::resetBookmarks() { readBookmarkList(); } bool Smb4KBookmarkHandler::isBookmarked(const SharePtr& share) { if (findBookmarkByUrl(share->url())) { return true; } return false; } void Smb4KBookmarkHandler::editBookmarks() { // // Only allow one instance of the bookmark editor // if (!d->editor) { d->editor = new Smb4KBookmarkEditor(d->bookmarks, QApplication::activeWindow()); } else { d->editor->raise(); } if (d->editor->exec() == QDialog::Accepted) { addBookmarks(d->editor->editedBookmarks(), true); } else { resetBookmarks(); } // // Delete the editor after use // delete d->editor; d->editor = 0; } void Smb4KBookmarkHandler::update() const { // Get new IP addresses. for (const BookmarkPtr &bookmark : d->bookmarks) { HostPtr host = findHost(bookmark->hostName(), bookmark->workgroupName()); if (host) { if (host->hasIpAddress() && bookmark->hostIpAddress() != host->ipAddress()) { bookmark->setHostIpAddress(host->ipAddress()); } } } } void Smb4KBookmarkHandler::migrateProfile(const QString& from, const QString& to) { // Replace the old profile name with the new one. for (const BookmarkPtr &bookmark : d->bookmarks) { if (QString::compare(bookmark->profile(), from, Qt::CaseSensitive) == 0) { bookmark->setProfile(to); } } // Write the new list to the file. writeBookmarkList(); } void Smb4KBookmarkHandler::removeProfile(const QString& name) { QMutableListIterator it(d->bookmarks); while (it.hasNext()) { const BookmarkPtr &bookmark = it.next(); if (QString::compare(bookmark->profile(), name, Qt::CaseSensitive) == 0) { it.remove(); } } // Write the new list to the file. writeBookmarkList(); } diff --git a/core/smb4kbookmarkhandler_p.cpp b/core/smb4kbookmarkhandler_p.cpp index 799a85b..532cc1f 100644 --- a/core/smb4kbookmarkhandler_p.cpp +++ b/core/smb4kbookmarkhandler_p.cpp @@ -1,969 +1,971 @@ /*************************************************************************** Private classes for the bookmark handler ------------------- begin : Sun Mar 20 2011 copyright : (C) 2011-2018 by Alexander Reinholdt email : alexander.reinholdt@kdemail.net ***************************************************************************/ /*************************************************************************** * 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, 51 Franklin Street, Suite 500, Boston, * * MA 02110-1335, USA * ***************************************************************************/ #ifdef HAVE_CONFIG_H #include #endif // application specific includes #include "smb4kbookmarkhandler_p.h" #include "smb4ksettings.h" #include "smb4kbookmark.h" // Qt includes #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include +#include // KDE includes #define TRANSLATION_DOMAIN "smb4k-core" #include #include #include Smb4KBookmarkDialog::Smb4KBookmarkDialog(const QList &bookmarks, const QStringList &groups, QWidget *parent) : QDialog(parent) { setWindowTitle(i18n("Add Bookmarks")); setupView(); loadLists(bookmarks, groups); + create(); + KConfigGroup group(Smb4KSettings::self()->config(), "BookmarkDialog"); KWindowConfig::restoreWindowSize(windowHandle(), group); + resize(windowHandle()->size()); // workaround for QTBUG-40584 + m_label_edit->completionObject()->setItems(group.readEntry("LabelCompletion", QStringList())); m_group_combo->completionObject()->setItems(group.readEntry("GroupCompletion", m_groups)); connect(KIconLoader::global(), SIGNAL(iconChanged(int)), SLOT(slotIconSizeChanged(int))); } Smb4KBookmarkDialog::~Smb4KBookmarkDialog() { while (!m_bookmarks.isEmpty()) { m_bookmarks.takeFirst().clear(); } } const QList &Smb4KBookmarkDialog::bookmarks() { return m_bookmarks; } void Smb4KBookmarkDialog::setupView() { QVBoxLayout *layout = new QVBoxLayout(this); layout->setSpacing(5); QWidget *description = new QWidget(this); QHBoxLayout *desc_layout = new QHBoxLayout(description); desc_layout->setSpacing(5); desc_layout->setMargin(0); QLabel *pixmap = new QLabel(description); QPixmap sync_pix = KDE::icon("bookmark-new").pixmap(KIconLoader::SizeHuge); pixmap->setPixmap(sync_pix); pixmap->setAlignment(Qt::AlignBottom); QLabel *label = new QLabel(i18n("All listed shares will be bookmarked. To edit the label " "or group, click the respective bookmark entry."), description); label->setWordWrap(true); label->setAlignment(Qt::AlignBottom); desc_layout->addWidget(pixmap, 0); desc_layout->addWidget(label, Qt::AlignBottom); m_widget = new QListWidget(this); m_widget->setSortingEnabled(true); m_widget->setSelectionMode(QAbstractItemView::SingleSelection); int icon_size = KIconLoader::global()->currentSize(KIconLoader::Small); m_widget->setIconSize(QSize(icon_size, icon_size)); m_editors = new QWidget(this); m_editors->setEnabled(false); QGridLayout *editors_layout = new QGridLayout(m_editors); editors_layout->setSpacing(5); editors_layout->setMargin(0); QLabel *l_label = new QLabel(i18n("Label:"), m_editors); m_label_edit = new KLineEdit(m_editors); m_label_edit->setClearButtonEnabled(true); QLabel *g_label = new QLabel(i18n("Group:"), m_editors); m_group_combo = new KComboBox(true, m_editors); editors_layout->addWidget(l_label, 0, 0, 0); editors_layout->addWidget(m_label_edit, 0, 1, 0); editors_layout->addWidget(g_label, 1, 0, 0); editors_layout->addWidget(m_group_combo, 1, 1, 0); QDialogButtonBox *buttonBox = new QDialogButtonBox(Qt::Horizontal, this); m_ok_button = buttonBox->addButton(QDialogButtonBox::Ok); m_cancel_button = buttonBox->addButton(QDialogButtonBox::Cancel); m_ok_button->setShortcut(Qt::CTRL|Qt::Key_Return); m_cancel_button->setShortcut(Qt::Key_Escape); m_ok_button->setDefault(true); layout->addWidget(description, 0); layout->addWidget(m_widget, 0); layout->addWidget(m_editors, 0); layout->addWidget(buttonBox, 0); - setMinimumWidth(sizeHint().width() > 350 ? sizeHint().width() : 350); - // // Connections // connect(m_widget, SIGNAL(itemClicked(QListWidgetItem*)), this, SLOT(slotBookmarkClicked(QListWidgetItem*))); connect(m_label_edit, SIGNAL(editingFinished()), this, SLOT(slotLabelEdited())); connect(m_group_combo->lineEdit(), SIGNAL(editingFinished()), this, SLOT(slotGroupEdited())); connect(m_ok_button, SIGNAL(clicked()), this, SLOT(slotDialogAccepted())); connect(m_cancel_button, SIGNAL(clicked()), this, SLOT(reject())); } void Smb4KBookmarkDialog::loadLists(const QList &bookmarks, const QStringList &groups) { // Copy the bookmarks to the internal list and add them to // the list widget afterwards. for (const BookmarkPtr &b : bookmarks) { QListWidgetItem *item = new QListWidgetItem(b->icon(), b->displayString(), m_widget); item->setData(Qt::UserRole, static_cast(b->url())); m_bookmarks << b; } m_groups = groups; m_group_combo->addItems(m_groups); } BookmarkPtr Smb4KBookmarkDialog::findBookmark(const QUrl &url) { BookmarkPtr bookmark; for (const BookmarkPtr &b : m_bookmarks) { if (b->url() == url) { bookmark = b; break; } else { continue; } } return bookmark; } void Smb4KBookmarkDialog::slotBookmarkClicked(QListWidgetItem *bookmark_item) { if (bookmark_item) { // Enable the editor widgets if necessary if (!m_editors->isEnabled()) { m_editors->setEnabled(true); } QUrl url = bookmark_item->data(Qt::UserRole).toUrl(); BookmarkPtr bookmark = findBookmark(url); if (bookmark) { m_label_edit->setText(bookmark->label()); m_group_combo->setCurrentItem(bookmark->groupName()); } else { m_label_edit->clear(); m_group_combo->clearEditText(); m_editors->setEnabled(false); } } else { m_label_edit->clear(); m_group_combo->clearEditText(); m_editors->setEnabled(false); } } void Smb4KBookmarkDialog::slotLabelEdited() { // Set the label QUrl url = m_widget->currentItem()->data(Qt::UserRole).toUrl(); BookmarkPtr bookmark = findBookmark(url); if (bookmark) { bookmark->setLabel(m_label_edit->userText()); } // Add label to completion object KCompletion *completion = m_label_edit->completionObject(); if (!m_label_edit->userText().isEmpty()) { completion->addItem(m_label_edit->userText()); } } void Smb4KBookmarkDialog::slotGroupEdited() { // Set the group QUrl url = m_widget->currentItem()->data(Qt::UserRole).toUrl(); BookmarkPtr bookmark = findBookmark(url); if (bookmark) { bookmark->setGroupName(m_group_combo->currentText()); } // Add the group name to the combo box if (m_group_combo->findText(m_group_combo->currentText()) == -1) { m_group_combo->addItem(m_group_combo->currentText()); } // Add group to completion object KCompletion *completion = m_group_combo->completionObject(); if (!m_group_combo->currentText().isEmpty()) { completion->addItem(m_group_combo->currentText()); } } void Smb4KBookmarkDialog::slotDialogAccepted() { KConfigGroup group(Smb4KSettings::self()->config(), "BookmarkDialog"); KWindowConfig::saveWindowSize(windowHandle(), group); group.writeEntry("LabelCompletion", m_label_edit->completionObject()->items()); group.writeEntry("GroupCompletion", m_group_combo->completionObject()->items()); accept(); } void Smb4KBookmarkDialog::slotIconSizeChanged(int group) { switch (group) { case KIconLoader::Small: { int icon_size = KIconLoader::global()->currentSize(KIconLoader::Small); m_widget->setIconSize(QSize(icon_size, icon_size)); break; } default: { break; } } } Smb4KBookmarkEditor::Smb4KBookmarkEditor(const QList &bookmarks, QWidget *parent) : QDialog(parent), m_bookmarks(bookmarks) { // // Set the window title // setWindowTitle(i18n("Edit Bookmarks")); // // Setup the view // setupView(); // // Load the bookmarks into the editor // loadBookmarks(); - // - // Set the editor's minimum width - // - setMinimumWidth(sizeHint().height() > sizeHint().width() ? sizeHint().height() : sizeHint().width()); - // // Load some other settings - // + // + create(); + KConfigGroup group(Smb4KSettings::self()->config(), "BookmarkEditor"); KWindowConfig::restoreWindowSize(windowHandle(), group); + resize(windowHandle()->size()); + m_label_edit->completionObject()->setItems(group.readEntry("LabelCompletion", QStringList())); m_login_edit->completionObject()->setItems(group.readEntry("LoginCompletion", QStringList())); m_ip_edit->completionObject()->setItems(group.readEntry("IPCompletion", QStringList())); m_group_combo->completionObject()->setItems(group.readEntry("GroupCompletion", m_groups)); // // Connections // connect(KIconLoader::global(), SIGNAL(iconChanged(int)), SLOT(slotIconSizeChanged(int))); } Smb4KBookmarkEditor::~Smb4KBookmarkEditor() { while (!m_bookmarks.isEmpty()) { m_bookmarks.takeFirst().clear(); } } bool Smb4KBookmarkEditor::eventFilter(QObject *obj, QEvent *e) { if (obj == m_tree_widget->viewport()) { switch (e->type()) { case QEvent::DragEnter: { QDragEnterEvent *ev = static_cast(e); if (ev->source() == m_tree_widget->viewport()) { e->accept(); } else { e->ignore(); } break; } case QEvent::DragLeave: { e->ignore(); break; } case QEvent::Drop: { QTimer::singleShot(50, this, SLOT(slotAdjust())); break; } default: { break; } } } return QDialog::eventFilter(obj, e); } void Smb4KBookmarkEditor::setupView() { QVBoxLayout *layout = new QVBoxLayout(this); layout->setSpacing(5); m_tree_widget = new QTreeWidget(this); m_tree_widget->setColumnCount(2); m_tree_widget->hideColumn((m_tree_widget->columnCount() - 1)); // for sorting purposes m_tree_widget->headerItem()->setHidden(true); m_tree_widget->setRootIsDecorated(true); m_tree_widget->setSelectionMode(QAbstractItemView::SingleSelection); m_tree_widget->setContextMenuPolicy(Qt::CustomContextMenu); m_tree_widget->header()->setSectionResizeMode(QHeaderView::ResizeToContents); m_tree_widget->setDragDropMode(QTreeWidget::InternalMove); int icon_size = KIconLoader::global()->currentSize(KIconLoader::Small); m_tree_widget->setIconSize(QSize(icon_size, icon_size)); m_tree_widget->viewport()->installEventFilter(this); m_add_group = new QAction(KDE::icon("bookmark-add-folder"), i18n("Add Group"), m_tree_widget); m_delete = new QAction(KDE::icon("edit-delete"), i18n("Remove"), m_tree_widget); m_clear = new QAction(KDE::icon("edit-clear"), i18n("Clear"), m_tree_widget); m_menu = new KActionMenu(m_tree_widget); m_menu->addAction(m_add_group); m_menu->addAction(m_delete); m_menu->addAction(m_clear); m_editors = new QWidget(this); m_editors->setEnabled(false); QGridLayout *editors_layout = new QGridLayout(m_editors); editors_layout->setSpacing(5); editors_layout->setMargin(0); QLabel *l_label = new QLabel(i18n("Label:"), m_editors); m_label_edit = new KLineEdit(m_editors); m_label_edit->setClearButtonEnabled(true); QLabel *lg_label = new QLabel(i18n("Login:"), m_editors); m_login_edit = new KLineEdit(m_editors); m_login_edit->setClearButtonEnabled(true); QLabel *i_label = new QLabel(i18n("IP Address:"), m_editors); m_ip_edit = new KLineEdit(m_editors); m_ip_edit->setClearButtonEnabled(true); QLabel *g_label = new QLabel(i18n("Group:"), m_editors); m_group_combo = new KComboBox(true, m_editors); m_group_combo->setDuplicatesEnabled(false); editors_layout->addWidget(l_label, 0, 0, 0); editors_layout->addWidget(m_label_edit, 0, 1, 0); editors_layout->addWidget(lg_label, 1, 0, 0); editors_layout->addWidget(m_login_edit, 1, 1, 0); editors_layout->addWidget(i_label, 2, 0, 0); editors_layout->addWidget(m_ip_edit, 2, 1, 0); editors_layout->addWidget(g_label, 3, 0, 0); editors_layout->addWidget(m_group_combo, 3, 1, 0); QDialogButtonBox *buttonBox = new QDialogButtonBox(Qt::Horizontal, this); m_ok_button = buttonBox->addButton(QDialogButtonBox::Ok); m_cancel_button = buttonBox->addButton(QDialogButtonBox::Cancel); m_ok_button->setShortcut(Qt::CTRL|Qt::Key_Return); m_cancel_button->setShortcut(Qt::Key_Escape); m_ok_button->setDefault(true); layout->addWidget(m_tree_widget); layout->addWidget(m_editors); layout->addWidget(buttonBox); // // Connections // connect(m_tree_widget, SIGNAL(itemClicked(QTreeWidgetItem*,int)), this, SLOT(slotItemClicked(QTreeWidgetItem*,int))); connect(m_tree_widget, SIGNAL(customContextMenuRequested(QPoint)), this, SLOT(slotContextMenuRequested(QPoint))); connect(m_label_edit, SIGNAL(editingFinished()), this, SLOT(slotLabelEdited())); connect(m_ip_edit, SIGNAL(editingFinished()), this, SLOT(slotIPEdited())); connect(m_login_edit, SIGNAL(editingFinished()), this, SLOT(slotLoginEdited())); connect(m_group_combo->lineEdit(), SIGNAL(editingFinished()), this, SLOT(slotGroupEdited())); connect(m_add_group, SIGNAL(triggered(bool)), this, SLOT(slotAddGroupTriggered(bool))); connect(m_delete, SIGNAL(triggered(bool)), this, SLOT(slotDeleteTriggered(bool))); connect(m_clear, SIGNAL(triggered(bool)), this, SLOT(slotClearTriggered(bool))); connect(m_ok_button, SIGNAL(clicked()), this, SLOT(slotDialogAccepted())); connect(m_cancel_button, SIGNAL(clicked()), this, SLOT(slotDialogRejected())); } void Smb4KBookmarkEditor::loadBookmarks() { // // Clear the tree widget and the group combo box // m_tree_widget->clear(); m_group_combo->clear(); // // Copy the groups into the internal list // m_groups.clear(); for (const BookmarkPtr &bookmark : m_bookmarks) { if (!m_groups.contains(bookmark->groupName())) { m_groups << bookmark->groupName(); } } // // Insert the groups into the tree widget // for (const QString &group : m_groups) { if (!group.isEmpty()) { QTreeWidgetItem *groupItem = new QTreeWidgetItem(QTreeWidgetItem::UserType); groupItem->setIcon(0, KDE::icon("folder-bookmark")); groupItem->setText(0, group); groupItem->setText((m_tree_widget->columnCount() - 1), QString("00_%1").arg(group)); groupItem->setFlags(Qt::ItemIsSelectable|Qt::ItemIsUserCheckable|Qt::ItemIsEnabled|Qt::ItemIsDropEnabled); m_tree_widget->addTopLevelItem(groupItem); } } // // Insert the bookmarks info the tree widget // for (const BookmarkPtr &bookmark : m_bookmarks) { QTreeWidgetItem *bookmarkItem = new QTreeWidgetItem(QTreeWidgetItem::UserType); bookmarkItem->setData(0, QTreeWidgetItem::UserType, static_cast(bookmark->url())); bookmarkItem->setIcon(0, bookmark->icon()); bookmarkItem->setText(0, bookmark->displayString()); bookmarkItem->setText((m_tree_widget->columnCount() - 1), QString("01_%1").arg(bookmark->url().toString(QUrl::RemoveUserInfo|QUrl::RemovePort))); bookmarkItem->setFlags(Qt::ItemIsSelectable|Qt::ItemIsUserCheckable|Qt::ItemIsEnabled|Qt::ItemIsDragEnabled); if (!bookmark->groupName().isEmpty()) { QList items = m_tree_widget->findItems(bookmark->groupName(), Qt::MatchFixedString|Qt::MatchCaseSensitive, 0); if (!items.isEmpty()) { items.first()->addChild(bookmarkItem); items.first()->setExpanded(true); } } else { m_tree_widget->addTopLevelItem(bookmarkItem); } } // // Sort // for (int i = 0; i < m_tree_widget->topLevelItemCount(); ++i) { m_tree_widget->topLevelItem(i)->sortChildren((m_tree_widget->columnCount() - 1), Qt::AscendingOrder); } m_tree_widget->sortItems((m_tree_widget->columnCount() - 1), Qt::AscendingOrder); // // Check that an empty group entry is also present. If it is not there, // add it now and insert the groups to the group combo box afterwards. // if (!m_groups.contains("") && !m_groups.contains(QString())) { m_groups << ""; } m_group_combo->addItems(m_groups); m_group_combo->setCurrentItem(""); } QList Smb4KBookmarkEditor::editedBookmarks() { return m_bookmarks; } BookmarkPtr Smb4KBookmarkEditor::findBookmark(const QUrl &url) { BookmarkPtr bookmark; for (const BookmarkPtr &b : m_bookmarks) { if (b->url() == url) { bookmark = b; break; } else { continue; } } return bookmark; } void Smb4KBookmarkEditor::slotItemClicked(QTreeWidgetItem *item, int /*col*/) { if (item) { if (m_tree_widget->indexOfTopLevelItem(item) != -1) { // This is a top-level item, i.e. it is either a bookmark without // group or a group entry. // Bookmarks have an URL stored, group folders not. if (!item->data(0, QTreeWidgetItem::UserType).toUrl().isEmpty()) { BookmarkPtr bookmark = findBookmark(item->data(0, QTreeWidgetItem::UserType).toUrl()); if (bookmark) { m_label_edit->setText(bookmark->label()); m_login_edit->setText(bookmark->login()); m_ip_edit->setText(bookmark->hostIpAddress()); m_group_combo->setCurrentItem(bookmark->groupName()); m_editors->setEnabled(true); } else { m_label_edit->clear(); m_login_edit->clear(); m_ip_edit->clear(); m_group_combo->clearEditText(); m_editors->setEnabled(false); } } else { m_label_edit->clear(); m_login_edit->clear(); m_ip_edit->clear(); m_group_combo->clearEditText(); m_editors->setEnabled(false); } } else { // This can only be a bookmark. BookmarkPtr bookmark = findBookmark(item->data(0, QTreeWidgetItem::UserType).toUrl()); if (bookmark) { m_label_edit->setText(bookmark->label()); m_login_edit->setText(bookmark->login()); m_ip_edit->setText(bookmark->hostIpAddress()); m_group_combo->setCurrentItem(bookmark->groupName()); m_editors->setEnabled(true); } else { m_label_edit->clear(); m_login_edit->clear(); m_ip_edit->clear(); m_group_combo->clearEditText(); m_editors->setEnabled(false); } } } else { m_label_edit->clear(); m_login_edit->clear(); m_ip_edit->clear(); m_group_combo->clearEditText(); m_editors->setEnabled(false); } } void Smb4KBookmarkEditor::slotContextMenuRequested(const QPoint &pos) { QTreeWidgetItem *item = m_tree_widget->itemAt(pos); m_delete->setEnabled((item)); m_menu->menu()->popup(m_tree_widget->viewport()->mapToGlobal(pos)); } void Smb4KBookmarkEditor::slotLabelEdited() { // Set the label QUrl url = m_tree_widget->currentItem()->data(0, QTreeWidgetItem::UserType).toUrl(); BookmarkPtr bookmark = findBookmark(url); if (bookmark) { bookmark->setLabel(m_label_edit->userText()); } // Add label to completion object KCompletion *completion = m_label_edit->completionObject(); if (!m_label_edit->userText().isEmpty()) { completion->addItem(m_label_edit->userText()); } } void Smb4KBookmarkEditor::slotLoginEdited() { // Set the login QUrl url = m_tree_widget->currentItem()->data(0, QTreeWidgetItem::UserType).toUrl(); BookmarkPtr bookmark = findBookmark(url); if (bookmark) { bookmark->setLogin(m_login_edit->userText()); } // Add login to completion object KCompletion *completion = m_login_edit->completionObject(); if (!m_login_edit->userText().isEmpty()) { completion->addItem(m_login_edit->userText()); } } void Smb4KBookmarkEditor::slotIPEdited() { // Set the ip address QUrl url = m_tree_widget->currentItem()->data(0, QTreeWidgetItem::UserType).toUrl(); BookmarkPtr bookmark = findBookmark(url); if (bookmark) { bookmark->setHostIpAddress(m_ip_edit->userText()); } // Add login to completion object KCompletion *completion = m_ip_edit->completionObject(); if (!m_ip_edit->userText().isEmpty()) { completion->addItem(m_ip_edit->userText()); } } void Smb4KBookmarkEditor::slotGroupEdited() { // // Get the URL of the current item. // QUrl url = m_tree_widget->currentItem()->data(0, QTreeWidgetItem::UserType).toUrl(); // // Return here, if the current item is a group // if (url.isEmpty()) { return; } // // Set the group name to the bookmark // BookmarkPtr bookmark = findBookmark(url); if (bookmark) { bookmark->setGroupName(m_group_combo->currentText()); } // // Reload the bookmarks (The current item is cleared by this!) // loadBookmarks(); // // Reset the current item // QTreeWidgetItemIterator it(m_tree_widget); while (*it) { if ((*it)->data(0, QTreeWidgetItem::UserType).toUrl() == url) { m_tree_widget->setCurrentItem(*it); slotItemClicked(*it, 0); break; } ++it; } // // Add the group to the completion object // KCompletion *completion = m_group_combo->completionObject(); if (!m_group_combo->currentText().isEmpty()) { completion->addItem(m_group_combo->currentText()); } } void Smb4KBookmarkEditor::slotAddGroupTriggered(bool /*checked*/) { bool ok = false; QString group_name = QInputDialog::getText(this, i18n("Add Group"), i18n("Group name:"), QLineEdit::Normal, QString(), &ok); if (ok && !group_name.isEmpty() && m_tree_widget->findItems(group_name, Qt::MatchFixedString|Qt::MatchCaseSensitive, 0).isEmpty()) { // Create a new group item and add it to the widget QTreeWidgetItem *group = new QTreeWidgetItem(QTreeWidgetItem::UserType); group->setIcon(0, KDE::icon("folder-bookmark")); group->setText(0, group_name); group->setText((m_tree_widget->columnCount() - 1), QString("00_%1").arg(group_name)); group->setFlags(Qt::ItemIsSelectable|Qt::ItemIsUserCheckable|Qt::ItemIsEnabled|Qt::ItemIsDropEnabled) ; m_tree_widget->addTopLevelItem(group); m_tree_widget->sortItems((m_tree_widget->columnCount() - 1), Qt::AscendingOrder); // Add the group to the combo box m_group_combo->addItem(group_name); m_group_combo->completionObject()->addItem(group_name); } } void Smb4KBookmarkEditor::slotDeleteTriggered(bool /*checked*/) { // // Remove the bookmarks from the view and the internal list // QList selected = m_tree_widget->selectedItems(); while (!selected.isEmpty()) { QTreeWidgetItem *item = selected.takeFirst(); QUrl url = item->data(0, QTreeWidgetItem::UserType).toUrl(); QMutableListIterator it(m_bookmarks); while (it.hasNext()) { BookmarkPtr bookmark = it.next(); if (bookmark->url() == url) { it.remove(); break; } } delete item; } } void Smb4KBookmarkEditor::slotClearTriggered(bool /*checked*/) { m_tree_widget->clear(); m_bookmarks.clear(); m_groups.clear(); } void Smb4KBookmarkEditor::slotDialogAccepted() { // // Write the dialog properties to the config file // KConfigGroup group(Smb4KSettings::self()->config(), "BookmarkEditor"); KWindowConfig::saveWindowSize(windowHandle(), group); group.writeEntry("LabelCompletion", m_label_edit->completionObject()->items()); group.writeEntry("LoginCompletion", m_login_edit->completionObject()->items()); group.writeEntry("IPCompletion", m_ip_edit->completionObject()->items()); group.writeEntry("GroupCompletion", m_group_combo->completionObject()->items()); // // Accept the dialog // accept(); } void Smb4KBookmarkEditor::slotDialogRejected() { // // Reject the dialog // reject(); } void Smb4KBookmarkEditor::slotIconSizeChanged(int group) { switch (group) { case KIconLoader::Small: { int icon_size = KIconLoader::global()->currentSize(KIconLoader::Small); m_tree_widget->setIconSize(QSize(icon_size, icon_size)); break; } default: { break; } } } void Smb4KBookmarkEditor::slotAdjust() { // Do the necessary adjustments: QTreeWidgetItemIterator it(m_tree_widget); while (*it) { if (!(*it)->parent()) { if ((*it)->data(0, QTreeWidgetItem::UserType).toUrl().isEmpty()) { if ((*it)->childCount() == 0) { delete *it; } } else { BookmarkPtr bookmark = findBookmark((*it)->data(0, QTreeWidgetItem::UserType).toUrl()); if (bookmark) { bookmark->setGroupName(""); } } } else { BookmarkPtr bookmark = findBookmark((*it)->data(0, QTreeWidgetItem::UserType).toUrl()); if (bookmark) { bookmark->setGroupName((*it)->parent()->text(0)); } } ++it; } } diff --git a/core/smb4kmounter_p.cpp b/core/smb4kmounter_p.cpp index 7489eef..c883dd6 100644 --- a/core/smb4kmounter_p.cpp +++ b/core/smb4kmounter_p.cpp @@ -1,273 +1,275 @@ /*************************************************************************** This file contains private helper classes for the Smb4KMounter class. ------------------- begin : Do Jul 19 2007 copyright : (C) 2007-2019 by Alexander Reinholdt email : alexander.reinholdt@kdemail.net ***************************************************************************/ /*************************************************************************** * 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, Suite 500, Boston,* * MA 02110-1335, USA * ***************************************************************************/ #ifdef HAVE_CONFIG_H #include #endif // application specific includes #include "smb4kmounter_p.h" #include "smb4ksettings.h" #include "smb4knotification.h" #include "smb4khomesshareshandler.h" #include "smb4kglobal.h" #include "smb4kcustomoptions.h" #include "smb4kcustomoptionsmanager.h" // Qt includes #include #include #include #include #include #include +#include // KDE includes #define TRANSLATION_DOMAIN "smb4k-core" #include #include #include using namespace Smb4KGlobal; Smb4KMountDialog::Smb4KMountDialog(const SharePtr &share, QWidget *parent) : QDialog(parent), m_share(share), m_valid(true) { setWindowTitle(i18n("Mount Share")); setupView(); - - setMinimumWidth(sizeHint().width() > 350 ? sizeHint().width() : 350); + + create(); KConfigGroup group(Smb4KSettings::self()->config(), "MountDialog"); - KWindowConfig::saveWindowSize(windowHandle(), group); + KWindowConfig::restoreWindowSize(windowHandle(), group); + resize(windowHandle()->size()); // workaround for QTBUG-40584 m_share_input->completionObject()->setItems(group.readEntry("ShareNameCompletion", QStringList())); m_ip_input->completionObject()->setItems(group.readEntry("IPAddressCompletion", QStringList())); m_workgroup_input->completionObject()->setItems(group.readEntry("WorkgroupCompletion", QStringList())); } Smb4KMountDialog::~Smb4KMountDialog() { } void Smb4KMountDialog::setupView() { QVBoxLayout *layout = new QVBoxLayout(this); layout->setSpacing(5); QWidget *description = new QWidget(this); QHBoxLayout *desc_layout = new QHBoxLayout(description); desc_layout->setSpacing(5); QLabel *pixmap = new QLabel(description); QPixmap mount_pix = KDE::icon("view-form", QStringList("emblem-mounted")).pixmap(KIconLoader::SizeHuge); pixmap->setPixmap(mount_pix); pixmap->setAlignment(Qt::AlignBottom); QLabel *label = new QLabel(i18n("Enter the location and optionally the IP address and workgroup to mount a share."), description); label->setWordWrap(true); label->setAlignment(Qt::AlignBottom); desc_layout->addWidget(pixmap, 0); desc_layout->addWidget(label, Qt::AlignBottom); QWidget *edit_widget = new QWidget(this); QGridLayout *edit_layout = new QGridLayout(edit_widget); layout->setSpacing(5); QLabel *shareLabel = new QLabel(i18n("Location:"), edit_widget); m_share_input = new KLineEdit(edit_widget); m_share_input->setWhatsThis(i18n("The location of the share is provided by the Uniform Resource Locator (URL). It generally has the following syntax: " "[smb:]//[USER:PASSWORD@]HOST:PORT/SHARE. The username, password and port are optional. You should omit to enter the password here, because it is shown in cleartext.")); // m_share_input->setToolTip(i18n("The URL of the share")); m_share_input->setCompletionMode(KCompletion::CompletionPopupAuto); m_share_input->setClearButtonEnabled(true); m_share_input->setMinimumWidth(200); m_share_input->setFocus(); QLabel *addressLabel = new QLabel(i18n("IP Address:"), edit_widget); m_ip_input = new KLineEdit(edit_widget); m_ip_input->setWhatsThis(i18n("The Internet Protocol (IP) address identifies the " "host in the network and indicates where it is. It has two valid formats, the one " "known as IP version 4 (e.g. 192.168.2.11) and the version 6 format " "(e.g. 2001:0db8:85a3:08d3:1319:8a2e:0370:7334).")); // m_ip_input->setToolTip(i18n("The IP address of the host where the share is located")); m_ip_input->setCompletionMode(KCompletion::CompletionPopupAuto); m_ip_input->setClearButtonEnabled(true); m_ip_input->setMinimumWidth(200); QLabel *workgroupLabel = new QLabel(i18n("Workgroup:"), edit_widget); m_workgroup_input = new KLineEdit(edit_widget); m_workgroup_input->setWhatsThis(i18n("The workgroup or domain identifies the " "peer-to-peer computer network the host is located in.")); // m_workgroup_input->setToolTip(i18n("The workgroup where the host is located")); m_workgroup_input->setCompletionMode(KCompletion::CompletionPopupAuto); m_workgroup_input->setClearButtonEnabled(true); m_workgroup_input->setMinimumWidth(200); edit_layout->addWidget(shareLabel, 0, 0, 0); edit_layout->addWidget(m_share_input, 0, 1, 0); edit_layout->addWidget(addressLabel, 1, 0, 0); edit_layout->addWidget(m_ip_input, 1, 1, 0); edit_layout->addWidget(workgroupLabel, 2, 0, 0); edit_layout->addWidget(m_workgroup_input, 2, 1, 0); m_bookmark = new QCheckBox(i18n("Add this share to the bookmarks"), this); m_bookmark->setWhatsThis(i18n("If you tick this checkbox, the share will be bookmarked " "and you can access it e.g. through the \"Bookmarks\" menu entry in the main window.")); // m_bookmark->setToolTip(i18n("Add this share to the bookmarks")); QDialogButtonBox *buttonBox = new QDialogButtonBox(Qt::Horizontal, this); m_ok_button = buttonBox->addButton(QDialogButtonBox::Ok); m_cancel_button = buttonBox->addButton(QDialogButtonBox::Cancel); m_ok_button->setShortcut(Qt::CTRL|Qt::Key_Return); m_cancel_button->setShortcut(Qt::Key_Escape); layout->addWidget(description, Qt::AlignBottom); layout->addWidget(edit_widget, 0); layout->addWidget(m_bookmark, 0); layout->addWidget(buttonBox, 0); slotChangeInputValue(m_share_input->text()); // // Connections // connect(m_share_input, SIGNAL(textChanged(QString)), this, SLOT(slotChangeInputValue(QString))); connect(m_share_input, SIGNAL(editingFinished()), this, SLOT(slotShareNameEntered())); connect(m_ip_input, SIGNAL(editingFinished()), this, SLOT(slotIPEntered())); connect(m_workgroup_input, SIGNAL(editingFinished()), this, SLOT(slotWorkgroupEntered())); connect(m_ok_button, SIGNAL(clicked()), this, SLOT(slotOkClicked())); connect(m_cancel_button, SIGNAL(clicked()), this, SLOT(slotCancelClicked())); } ///////////////////////////////////////////////////////////////////////////// // SLOT IMPLEMENTATIONS ///////////////////////////////////////////////////////////////////////////// void Smb4KMountDialog::slotChangeInputValue(const QString& _test) { m_ok_button->setEnabled(!_test.isEmpty()); } void Smb4KMountDialog::slotOkClicked() { if (!m_share_input->text().trimmed().isEmpty()) { // // Get the URL // QString userInput = m_share_input->text().trimmed(); // // Take care of a Windows-like UNC addresses // if (userInput.startsWith(QLatin1String("\\"))) { userInput.replace("\\", "/"); } // // Set the URL and adjust the scheme // QUrl smbUrl = QUrl::fromUserInput(userInput); smbUrl.setScheme("smb"); // // Set the URL of the share // if (smbUrl.isValid() && !smbUrl.host().isEmpty() && !smbUrl.path().isEmpty() && !smbUrl.path().endsWith(QLatin1String("/"))) { m_share->setUrl(smbUrl); m_share->setWorkgroupName(m_workgroup_input->text().trimmed()); m_share->setHostIpAddress(m_ip_input->text().trimmed()); } else { Smb4KNotification::invalidURLPassed(); m_valid = false; } } KConfigGroup group(Smb4KSettings::self()->config(), "MountDialog"); KWindowConfig::saveWindowSize(windowHandle(), group); group.writeEntry("ShareNameCompletion", m_share_input->completionObject()->items()); group.writeEntry("IPAddressCompletion", m_ip_input->completionObject()->items()); group.writeEntry("WorkgroupCompletion", m_workgroup_input->completionObject()->items()); accept(); } void Smb4KMountDialog::slotCancelClicked() { Smb4KMounter::self()->abort(); reject(); } void Smb4KMountDialog::slotShareNameEntered() { KCompletion *completion = m_share_input->completionObject(); QUrl url(m_share_input->userText()); url.setScheme("smb"); if (url.isValid() && !url.isEmpty()) { completion->addItem(m_share_input->userText()); } } void Smb4KMountDialog::slotIPEntered() { KCompletion *completion = m_ip_input->completionObject(); if (!m_ip_input->userText().isEmpty()) { completion->addItem(m_ip_input->userText()); } } void Smb4KMountDialog::slotWorkgroupEntered() { KCompletion *completion = m_workgroup_input->completionObject(); if (!m_workgroup_input->userText().isEmpty()) { completion->addItem(m_workgroup_input->userText()); } } diff --git a/core/smb4kmounter_p.h b/core/smb4kmounter_p.h index fcf1e22..a0725db 100644 --- a/core/smb4kmounter_p.h +++ b/core/smb4kmounter_p.h @@ -1,189 +1,189 @@ /*************************************************************************** This file contains private helper classes for the Smb4KMounter class. ------------------- begin : Do Jul 19 2007 copyright : (C) 2007-2019 by Alexander Reinholdt email : alexander.reinholdt@kdemail.net ***************************************************************************/ /*************************************************************************** * 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, Suite 500, Boston,* * MA 02110-1335, USA * ***************************************************************************/ #ifndef SMB4KMOUNTER_P_H #define SMB4KMOUNTER_P_H // application specific includes #include "smb4kmounter.h" #include "smb4kglobal.h" // Qt includes #include #include #include #include #include #include // KDE includes #include class Smb4KMountDialog : public QDialog { Q_OBJECT public: /** * The constructor. * * @param parent The parent widget */ - explicit Smb4KMountDialog(const SharePtr &share, - QWidget *parent = 0); + explicit Smb4KMountDialog(const SharePtr &share, QWidget *parent = 0); + /** * The destructor. */ ~Smb4KMountDialog(); /** * Returns if the share should be bookmarked or not. * * @returns TRUE if the share should be bookmarked */ bool bookmarkShare() { return m_bookmark->isChecked(); } /** * Returns if the user input is valid or not. * * @returns TRUE if the user input is valid. */ bool validUserInput() { return m_valid; } protected Q_SLOTS: /** * This slot is activated if the OK button has been clicked. */ void slotOkClicked(); /** * This slot is activated if the Cancel button has been clicked. */ void slotCancelClicked(); /** * This slot is being enabled if there is input text. * * @param text The input text. */ void slotChangeInputValue(const QString &text); /** * This slot is used for making text completion for the share edit line * work. */ void slotShareNameEntered(); /** * This slot is used for making text completion for the IP edit line * work. */ void slotIPEntered(); /** * This slot is used for making text completion for the workgroup edit * line work. */ void slotWorkgroupEntered(); private: /** * This function sets up the view. */ void setupView(); /** * The Ok button */ QPushButton *m_ok_button; /** * The Cancel button */ QPushButton *m_cancel_button; /** * The line edit where the user has to enter the share. */ KLineEdit *m_share_input; /** * The line edit where the user can enter the IP address. */ KLineEdit *m_ip_input; /** * The line edit where the user can enter the workgroup. */ KLineEdit *m_workgroup_input; /** * This checkbox determines whether the share should be added to the * bookmarks. */ QCheckBox *m_bookmark; /** * The share that is passed to the mounter. */ SharePtr m_share; /** * Valid user input? */ bool m_valid; }; class Smb4KMounterPrivate { public: int remountTimeout; int remountAttempts; int timerId; int checkTimeout; int newlyMounted; int newlyUnmounted; QPointer dialog; QList importedShares; QList retries; QList remounts; QString activeProfile; bool detectAllShares; bool mountShares; bool unmountShares; bool firstImportDone; }; class Smb4KMounterStatic { public: Smb4KMounter instance; }; #endif