Commit 312a97e4 authored by Alexander Reinholdt's avatar Alexander Reinholdt
Browse files

Improved the way shares are bookmarked in the mount dialog.

During this modification, also some members in class Smb4KBookmark were renamed and the code adjusted accordingly. Also, several bugs were identified and fixed.

BUG: 427478
parent 3cfc08fb
Pipeline #38828 passed with stage
in 11 minutes and 46 seconds
......@@ -2,7 +2,7 @@
This is the bookmark container for Smb4K (next generation).
-------------------
begin : So Jun 8 2008
copyright : (C) 2008-2019 by Alexander Reinholdt
copyright : (C) 2008-2020 by Alexander Reinholdt
email : alexander.reinholdt@kdemail.net
***************************************************************************/
......@@ -46,7 +46,7 @@ class Smb4KBookmarkPrivate
QString workgroup;
QHostAddress ip;
QString label;
QString group;
QString category;
QString profile;
QIcon icon;
Smb4KGlobal::ShareType type;
......@@ -203,15 +203,15 @@ QUrl Smb4KBookmark::url() const
}
void Smb4KBookmark::setGroupName(const QString &name)
void Smb4KBookmark::setCategoryName(const QString &name)
{
d->group = name;
d->category = name;
}
QString Smb4KBookmark::groupName() const
QString Smb4KBookmark::categoryName() const
{
return d->group;
return d->category;
}
......
......@@ -2,7 +2,7 @@
This is the bookmark container for Smb4K (next generation).
-------------------
begin : So Jun 8 2008
copyright : (C) 2008-2019 by Alexander Reinholdt
copyright : (C) 2008-2020 by Alexander Reinholdt
email : alexander.reinholdt@kdemail.net
***************************************************************************/
......@@ -199,23 +199,23 @@ class Q_DECL_EXPORT Smb4KBookmark
QUrl url() const;
/**
* Set the group this bookmark belongs to.
* Set the category this bookmark belongs to.
*
* @param name The group name
* @param name The category name
*/
void setGroupName(const QString &name);
void setCategoryName(const QString &name);
/**
* Returns the group name of this bookmark.
* Returns the name of the category this bookmark is in.
*
* @returns the group name
* @returns the category name
*/
QString groupName() const;
QString categoryName() const;
/**
* Sets the profile this bookmark belongs to. The profile is meant
* to distinguish between several network environments, like home
* and work, and is not an alternative to the group functions.
* and work, and is not an alternative to the categories.
*
* @param profile The profile name
*/
......
......@@ -2,7 +2,7 @@
This class handles the bookmarks.
-------------------
begin : Fr Jan 9 2004
copyright : (C) 2004-2019 by Alexander Reinholdt
copyright : (C) 2004-2020 by Alexander Reinholdt
email : alexander.reinholdt@kdemail.net
***************************************************************************/
......@@ -15,7 +15,7 @@
* 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. *
// * 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 *
......@@ -111,6 +111,41 @@ void Smb4KBookmarkHandler::addBookmark(const SharePtr &share)
}
void Smb4KBookmarkHandler::addBookmark(const BookmarkPtr &bookmark)
{
if (bookmark)
{
//
// Create a list that will be passed to addBookmarks()
//
QList<BookmarkPtr> bookmarks;
//
// Check if the share has already been bookmarked and skip it if it
// already exists
//
BookmarkPtr knownBookmark = findBookmarkByUrl(bookmark->url());
if (knownBookmark)
{
Smb4KNotification::bookmarkExists(knownBookmark.data());
return;
}
//
// Copy the bookmark and add the correct profile (may be empty)
//
BookmarkPtr newBookmark = BookmarkPtr(bookmark);
newBookmark->setProfile(Smb4KProfileManager::self()->activeProfile());
//
// Add the bookmark
//
addBookmarks(bookmarks, false);
}
}
void Smb4KBookmarkHandler::addBookmarks(const QList<SharePtr> &list)
{
//
......@@ -159,7 +194,7 @@ void Smb4KBookmarkHandler::addBookmarks(const QList<SharePtr> &list)
//
if (!newBookmarks.isEmpty())
{
QPointer<Smb4KBookmarkDialog> dlg = new Smb4KBookmarkDialog(newBookmarks, groupsList(), QApplication::activeWindow());
QPointer<Smb4KBookmarkDialog> dlg = new Smb4KBookmarkDialog(newBookmarks, categoryList(), QApplication::activeWindow());
if (dlg->exec() == QDialog::Accepted)
{
......@@ -254,7 +289,7 @@ void Smb4KBookmarkHandler::removeBookmark(const BookmarkPtr &bookmark)
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)
QString::compare(bookmark->categoryName(), d->bookmarks.at(i)->categoryName(), Qt::CaseInsensitive) == 0)
{
d->bookmarks.takeAt(i).clear();
break;
......@@ -268,7 +303,7 @@ void Smb4KBookmarkHandler::removeBookmark(const BookmarkPtr &bookmark)
}
void Smb4KBookmarkHandler::removeGroup(const QString& name)
void Smb4KBookmarkHandler::removeCategory(const QString& name)
{
QMutableListIterator<BookmarkPtr> it(d->bookmarks);
......@@ -277,7 +312,7 @@ void Smb4KBookmarkHandler::removeGroup(const QString& name)
const BookmarkPtr &b = it.next();
if ((!Smb4KSettings::useProfiles() || Smb4KSettings::activeProfile() == b->profile()) ||
QString::compare(b->groupName(), name, Qt::CaseInsensitive) == 0)
QString::compare(b->categoryName(), name, Qt::CaseInsensitive) == 0)
{
it.remove();
}
......@@ -301,7 +336,7 @@ void Smb4KBookmarkHandler::writeBookmarkList()
xmlWriter.setAutoFormatting(true);
xmlWriter.writeStartDocument();
xmlWriter.writeStartElement("bookmarks");
xmlWriter.writeAttribute("version", "2.0");
xmlWriter.writeAttribute("version", "3.0");
for (const BookmarkPtr &bookmark : d->bookmarks)
{
......@@ -313,7 +348,7 @@ void Smb4KBookmarkHandler::writeBookmarkList()
xmlWriter.writeStartElement("bookmark");
xmlWriter.writeAttribute("profile", bookmark->profile());
xmlWriter.writeAttribute("group", bookmark->groupName());
xmlWriter.writeAttribute("category", bookmark->categoryName());
xmlWriter.writeTextElement("workgroup", bookmark->workgroupName());
xmlWriter.writeTextElement("url", bookmark->url().toString(QUrl::RemoveUserInfo|QUrl::RemovePort));
......@@ -366,7 +401,7 @@ void Smb4KBookmarkHandler::readBookmarkList()
if (xmlReader.isStartElement())
{
if (xmlReader.name() == "bookmarks" &&
(xmlReader.attributes().value("version") != "1.1" && xmlReader.attributes().value("version") != "2.0"))
(xmlReader.attributes().value("version") != "2.0" && xmlReader.attributes().value("version") != "3.0"))
{
xmlReader.raiseError(i18n("The format of %1 is not supported.", xmlFile.fileName()));
break;
......@@ -379,7 +414,16 @@ void Smb4KBookmarkHandler::readBookmarkList()
BookmarkPtr bookmark = BookmarkPtr(new Smb4KBookmark());
bookmark->setProfile(profile);
bookmark->setGroupName(xmlReader.attributes().value("group").toString());
if (xmlReader.attributes().hasAttribute("group"))
{
// For backward compatibility (since Smb4K 3.0.72)
bookmark->setCategoryName(xmlReader.attributes().value("group").toString());
}
else
{
bookmark->setCategoryName(xmlReader.attributes().value("category").toString());
}
while (!(xmlReader.isEndElement() && xmlReader.name() == "bookmark"))
{
......@@ -391,10 +435,6 @@ void Smb4KBookmarkHandler::readBookmarkList()
{
bookmark->setWorkgroupName(xmlReader.readElementText());
}
else if (xmlReader.name() == "unc")
{
bookmark->setUrl(xmlReader.readElementText());
}
else if (xmlReader.name() == "url")
{
bookmark->setUrl(QUrl(xmlReader.readElementText()));
......@@ -530,17 +570,17 @@ QList<BookmarkPtr> Smb4KBookmarkHandler::bookmarksList() const
}
QList<BookmarkPtr> Smb4KBookmarkHandler::bookmarksList(const QString &group) const
QList<BookmarkPtr> Smb4KBookmarkHandler::bookmarksList(const QString &category) const
{
// Update bookmarks
update();
// Get the list of bookmarks organized in the given group
// Get the list of bookmarks organized in the given category
QList<BookmarkPtr> bookmarks;
for (const BookmarkPtr &bookmark : bookmarksList())
{
if (QString::compare(group, bookmark->groupName(), Qt::CaseInsensitive) == 0)
if (QString::compare(category, bookmark->categoryName(), Qt::CaseInsensitive) == 0)
{
bookmarks << bookmark;
}
......@@ -550,19 +590,19 @@ QList<BookmarkPtr> Smb4KBookmarkHandler::bookmarksList(const QString &group) con
}
QStringList Smb4KBookmarkHandler::groupsList() const
QStringList Smb4KBookmarkHandler::categoryList() const
{
QStringList groups;
QStringList categories;
for (const BookmarkPtr &b : bookmarksList())
{
if (!groups.contains(b->groupName()))
if (!categories.contains(b->categoryName()))
{
groups << b->groupName();
categories << b->categoryName();
}
}
return groups;
return categories;
}
......
......@@ -2,7 +2,7 @@
This class handles the bookmarks.
-------------------
begin : Fr Jan 9 2004
copyright : (C) 2004-2019 by Alexander Reinholdt
copyright : (C) 2004-2020 by Alexander Reinholdt
email : alexander.reinholdt@kdemail.net
***************************************************************************/
......@@ -81,6 +81,15 @@ class Q_DECL_EXPORT Smb4KBookmarkHandler : public QObject
* @param share The share that is to be bookmarked.
*/
void addBookmark(const SharePtr &share);
/**
* This function adds a new bookmark. The bookmark will be copied
* internally, so it is save to clear the bookmark pointer after
* it was passed to this function.
*
* @param bookmark The bookmark that is to be added.
*/
void addBookmark(const BookmarkPtr &bookmark);
/**
* This function adds several bookmarks at once. It takes a list of
......@@ -109,11 +118,11 @@ class Q_DECL_EXPORT Smb4KBookmarkHandler : public QObject
void removeBookmark(const BookmarkPtr &bookmark);
/**
* This function removes a group and all the bookmarks it contains.
* This function removes a category and all the bookmarks it contains.
*
* @param name The group name
*/
void removeGroup(const QString &name);
void removeCategory(const QString &name);
/**
* Get the list of bookmarks.
......@@ -124,13 +133,13 @@ class Q_DECL_EXPORT Smb4KBookmarkHandler : public QObject
QList<BookmarkPtr> bookmarksList() const;
/**
* Get the list of bookmarks belonging to a certain group.
* Get the list of bookmarks belonging to a certain category.
*
* @param group The name of the group the bookmarks are organized in
* @param category The name of the category the bookmarks are organized in
*
* @returns a list of bookmarks belonging to a certain group
* @returns a list of bookmarks belonging to a certain category
*/
QList<BookmarkPtr> bookmarksList(const QString &group) const;
QList<BookmarkPtr> bookmarksList(const QString &category) const;
/**
* This function searches for a bookmark using its URL and returns a pointer
......@@ -155,11 +164,11 @@ class Q_DECL_EXPORT Smb4KBookmarkHandler : public QObject
BookmarkPtr findBookmarkByLabel(const QString &label);
/**
* Returns the sorted list of bookmark groups.
* Returns the sorted list of bookmark categories.
*
* @returns the list of groups
* @returns the list of categories
*/
QStringList groupsList() const;
QStringList categoryList() const;
/**
* Reset the bookmarks by reloading them from the file.
......
This diff is collapsed.
......@@ -2,7 +2,7 @@
Private classes for the bookmark handler
-------------------
begin : Sun Mar 20 2011
copyright : (C) 2011-2018 by Alexander Reinholdt
copyright : (C) 2011-2020 by Alexander Reinholdt
email : alexander.reinholdt@kdemail.net
***************************************************************************/
......@@ -56,13 +56,11 @@ class Q_DECL_EXPORT Smb4KBookmarkDialog : public QDialog
*
* @param bookmarks The list of bookmarks that are to be saved
*
* @param groups The list of available bookmark groups
* @param categories The list of available bookmark categories
*
* @param parent The parent widget
*/
Smb4KBookmarkDialog(const QList<BookmarkPtr> &bookmarks,
const QStringList &groups,
QWidget *parent);
Smb4KBookmarkDialog(const QList<BookmarkPtr> &bookmarks, const QStringList &categories, QWidget *parent);
/**
* The destructor
......@@ -81,7 +79,7 @@ class Q_DECL_EXPORT Smb4KBookmarkDialog : public QDialog
/**
* Called when a bookmark was clicked in the list widget.
*/
void slotBookmarkClicked(QListWidgetItem *bookmark_item);
void slotBookmarkClicked(QListWidgetItem *bookmarkItem);
/**
* Called when the label is edited by the user
......@@ -89,9 +87,9 @@ class Q_DECL_EXPORT Smb4KBookmarkDialog : public QDialog
void slotLabelEdited();
/**
* Called when the group is edited by the user
* Called when the category is edited by the user
*/
void slotGroupEdited();
void slotCategoryEdited();
/**
* Called when the OK button was clicked
......@@ -110,24 +108,14 @@ class Q_DECL_EXPORT Smb4KBookmarkDialog : public QDialog
void setupView();
/**
* Load the list of bookmarks and the one of the groups
* Load the list of bookmarks and the one of the categories
*/
void loadLists(const QList<BookmarkPtr> &bookmarks, const QStringList &groups);
void loadLists(const QList<BookmarkPtr> &bookmarks, const QStringList &categories);
/**
* Finds the bookmark in the list
*/
BookmarkPtr findBookmark(const QUrl &url);
/**
* Ok push button
*/
QPushButton *m_ok_button;
/**
* Cancel push button
*/
QPushButton *m_cancel_button;
/**
* The list of bookmarks
......@@ -137,27 +125,7 @@ class Q_DECL_EXPORT Smb4KBookmarkDialog : public QDialog
/**
* The list of groups
*/
QStringList m_groups;
/**
* The tree widget for the potential bookmarks
*/
QListWidget *m_widget;
/**
* The widget containing the editors
*/
QWidget *m_editors;
/**
* The label
*/
KLineEdit *m_label_edit;
/**
* The groups
*/
KComboBox *m_group_combo;
QStringList m_categories;
};
......@@ -213,9 +181,9 @@ class Smb4KBookmarkEditor : public QDialog
void slotLabelEdited();
/**
* Called when the group is edited by the user
* Called when the category is edited by the user
*/
void slotGroupEdited();
void slotCategoryEdited();
/**
* Called when the IP address is edited by the user
......@@ -230,7 +198,7 @@ class Smb4KBookmarkEditor : public QDialog
/**
* Called when the add action was triggered
*/
void slotAddGroupTriggered(bool checked);
void slotAddCategoryTriggered(bool checked);
/**
* Called when the delete action was triggered
......@@ -272,76 +240,16 @@ class Smb4KBookmarkEditor : public QDialog
* Finds the bookmark in the list
*/
BookmarkPtr findBookmark(const QUrl &url);
/**
* Ok push button
*/
QPushButton *m_ok_button;
/**
* Cancel push button
*/
QPushButton *m_cancel_button;
/**
* List of the bookmarks that are being processed
*/
QList<BookmarkPtr> m_bookmarks;
/**
* Tree widget
*/
QTreeWidget *m_tree_widget;
/**
* The widget containing the editors
*/
QWidget *m_editors;
/**
* The label
*/
KLineEdit *m_label_edit;
/**
* The IP address
*/
KLineEdit *m_ip_edit;
/**
* The login
*/
KLineEdit *m_login_edit;
/**
* The groups
*/
KComboBox *m_group_combo;
/**
* The list of groups
*/
QStringList m_groups;
/**
* Action menu
*/
KActionMenu *m_menu;
/**
* Add group action
*/
QAction *m_add_group;
/**
* Delete action
*/
QAction *m_delete;
/**
* Clear action
*/
QAction *m_clear;
QStringList m_categories;
};
......
......@@ -88,7 +88,7 @@ Smb4KMounter::Smb4KMounter(QObject *parent)
d->checkTimeout = 0;
d->newlyMounted = 0;
d->newlyUnmounted = 0;
d->dialog = 0;
d->dialog = nullptr;
d->firstImportDone = false;
d->longActionRunning = false;
d->activeProfile = Smb4KProfileManager::self()->activeProfile();
......@@ -1000,8 +1000,9 @@ void Smb4KMounter::openMountDialog()
if (!d->dialog)
{
SharePtr share = SharePtr(new Smb4KShare());
BookmarkPtr bookmark = BookmarkPtr(new Smb4KBookmark());
d->dialog = new Smb4KMountDialog(share, QApplication::activeWindow());
d->dialog = new Smb4KMountDialog(share, bookmark, QApplication::activeWindow());
if (d->dialog->exec() == QDialog::Accepted && d->dialog->validUserInput())
{
......@@ -1011,14 +1012,15 @@ void Smb4KMounter::openMountDialog()
// Bookmark the share if the user wants this.
if (d->dialog->bookmarkShare())
{
Smb4KBookmarkHandler::self()->addBookmark(share);
Smb4KBookmarkHandler::self()->addBookmark(bookmark);
}
}
delete d->dialog;
d->dialog = 0;
d->dialog = nullptr;
share.clear();
bookmark.clear();
}
}
......
......@@ -2,7 +2,7 @@
This file contains private helper classes for the Smb4KMounter class.
-------------------
begin : Do Jul 19 2007
copyright : (C) 2007-2019 by Alexander Reinholdt
copyright : (C) 2007-2020 by Alexander Reinholdt
email : alexander.reinholdt@kdemail.net
***************************************************************************/
......@@ -31,6 +31,8 @@
#include "smb4kglobal.h"
#include "smb4kcustomoptions.h"
#include "smb4kcustomoptionsmanager.h"
#include "smb4kbookmarkhandler.h"
#include "smb4kbookmark.h"
// Qt includes
#include <QUrl>
......@@ -46,12 +48,14 @@
#include <KI18n/KLocalizedString>
#include <KConfigGui/KWindowConfig>
#include <KIconThemes/KIconLoader>
#include <KCompletion/KLineEdit>
#include <KCompletion/KComboBox>
using namespace Smb4KGlobal;
Smb4KMountDialog::Smb4KMountDialog(const SharePtr &share, QWidget *parent)
: QDialog(parent), m_share(share), m_valid(true)
Smb4KMountDialog::Smb4KMountDialog(const SharePtr &share, const BookmarkPtr &bookmark, QWidget *parent)
: QDialog(parent), m_share(share), m_bookmark(bookmark), m_valid(false)
{
//
// Set the title
......@@ -82,13 +86,36 @@ Smb4KMountDialog::Smb4KMountDialog(const SharePtr &share, QWidget *parent)
}
resize(dialogSize); // workaround for QTBUG-40584
setBaseSize(dialogSize);
//
// Get the widgets
//
KLineEdit *locationInput = findChild<KLineEdit *>("LocationInput");
KLineEdit *ipInput = findChild<KLineEdit *>("IpInput");
KLineEdit *workgroupInput = findChild<KLineEdit *>("WorkgroupInput");
KLineEdit *labelInput = findChild<KLineEdit *>("LabelInput");
KComboBox *categoryInput = findChild<KComboBox *>("CategoryInput");
//
// Fill the completion objects