diff --git a/src/providerpage.cpp b/src/providerpage.cpp index aa2b37a..affe05c 100644 --- a/src/providerpage.cpp +++ b/src/providerpage.cpp @@ -1,175 +1,182 @@ /* Copyright (c) 2009 Volker Krause Copyright (c) 2010 Tom Albers This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This library 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 Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #include "providerpage.h" #include "global.h" #include "accountwizard_debug.h" #include #include #include +#include ProviderPage::ProviderPage(KAssistantDialog *parent) : Page(parent) , m_model(new QStandardItemModel(this)) , m_downloadManager(new KNSCore::DownloadManager(this)) , m_newPageWanted(false) , m_newPageReady(false) { ui.setupUi(this); - QSortFilterProxyModel *proxy = new QSortFilterProxyModel(this); - proxy->setSourceModel(m_model); - ui.listView->setModel(proxy); - ui.searchLine->setProxy(proxy); - + mProxy = new QSortFilterProxyModel(this); + mProxy->setSourceModel(m_model); + mProxy->setFilterKeyColumn(-1); + mProxy->setFilterCaseSensitivity(Qt::CaseInsensitive); + ui.listView->setModel(mProxy); + connect(ui.searchLine, &QLineEdit::textChanged, this, &ProviderPage::slotTextChanged); m_fetchItem = new QStandardItem(i18n("Fetching provider list...")); m_model->appendRow(m_fetchItem); m_fetchItem->setFlags(Qt::NoItemFlags); // we can start the search, whenever the user reaches this page, chances // are we have the full list. connect(m_downloadManager, &KNSCore::DownloadManager::searchResult, this, &ProviderPage::fillModel); connect(m_downloadManager, &KNSCore::DownloadManager::entryStatusChanged, this, &ProviderPage::providerStatusChanged); m_downloadManager->setSearchOrder(KNSCore::DownloadManager::Alphabetical); connect(ui.listView->selectionModel(), &QItemSelectionModel::selectionChanged, this, &ProviderPage::selectionChanged); } void ProviderPage::startFetchingData() { m_downloadManager->search(0, 100000); } +void ProviderPage::slotTextChanged(const QString &str) +{ + mProxy->setFilterFixedString(str); +} + void ProviderPage::fillModel(const KNSCore::EntryInternal::List &list) { if (m_fetchItem) { m_model->removeRows(m_model->indexFromItem(m_fetchItem).row(), 1); m_fetchItem = nullptr; } // KNS3::Entry::Entry() is private, so we need to save the whole list. // we can not use a QHash or whatever, as that needs that constructor... m_providerEntries = list; for (const KNSCore::EntryInternal &e : list) { qCDebug(ACCOUNTWIZARD_LOG) << "Found Entry: " << e.name(); QStandardItem *item = new QStandardItem(e.name()); item->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled); item->setData(e.name(), Qt::ToolTipRole); item->setData(e.uniqueId(), Qt::UserRole); item->setData(e.providerId(), Qt::UserRole + 1); m_model->appendRow(item); } } void ProviderPage::selectionChanged() { if (ui.listView->selectionModel()->hasSelection()) { setValid(true); } else { setValid(false); } } void ProviderPage::leavePageNext() { m_newPageReady = false; if (!ui.listView->selectionModel()->hasSelection()) { return; } const QModelIndex index = ui.listView->selectionModel()->selectedIndexes().at(0); if (!index.isValid()) { return; } const QSortFilterProxyModel *proxy = static_cast(ui.listView->model()); const QStandardItem *item = m_model->itemFromIndex(proxy->mapToSource(index)); qCDebug(ACCOUNTWIZARD_LOG) << "Item selected:" << item->text(); // download and execute it... foreach (const KNSCore::EntryInternal &e, m_providerEntries) { if (e.uniqueId() == item->data(Qt::UserRole) && e.providerId() == item->data(Qt::UserRole + 1)) { m_wantedProvider.entryId = e.uniqueId(); m_wantedProvider.entryProviderId = e.providerId(); if (e.status() == KNS3::Entry::Installed) { qCDebug(ACCOUNTWIZARD_LOG) << "already installed" << e.installedFiles(); findDesktopAndSetAssistant(e.installedFiles()); } else { qCDebug(ACCOUNTWIZARD_LOG) << "Starting download for " << e.name(); m_downloadManager->installEntry(e); } break; } } } void ProviderPage::providerStatusChanged(const KNSCore::EntryInternal &e) { qCDebug(ACCOUNTWIZARD_LOG) << e.name(); if (e.uniqueId() == m_wantedProvider.entryId && e.providerId() == m_wantedProvider.entryProviderId && e.status() == KNS3::Entry::Installed) { findDesktopAndSetAssistant(e.installedFiles()); } } void ProviderPage::findDesktopAndSetAssistant(const QStringList &list) { for (const QString &file : list) { qCDebug(ACCOUNTWIZARD_LOG) << file; if (file.endsWith(QLatin1String(".desktop"))) { qCDebug(ACCOUNTWIZARD_LOG) << "Yay, a desktop file!" << file; Global::setAssistant(file); m_newPageReady = true; if (m_newPageWanted) { qCDebug(ACCOUNTWIZARD_LOG) << "New page was already requested, now we are done, approve it"; Q_EMIT leavePageNextOk(); } break; } } } QTreeView *ProviderPage::treeview() const { return ui.listView; } void ProviderPage::leavePageBackRequested() { Q_EMIT leavePageBackOk(); Q_EMIT ghnsNotWanted(); } void ProviderPage::leavePageNextRequested() { m_newPageWanted = true; if (m_newPageReady) { qCDebug(ACCOUNTWIZARD_LOG) << "New page requested and we are done, so ok..."; Q_EMIT leavePageNextOk(); } else { qCDebug(ACCOUNTWIZARD_LOG) << "New page requested, but we are not done yet..."; } } diff --git a/src/providerpage.h b/src/providerpage.h index 2ddc71b..eb7f8ea 100644 --- a/src/providerpage.h +++ b/src/providerpage.h @@ -1,73 +1,75 @@ /* Copyright (c) 2009 Volker Krause Copyright (c) 2010 Tom Albers This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This library 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 Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #ifndef PROVIDERPAGE_H #define PROVIDERPAGE_H #include "page.h" #include #include "ui_providerpage.h" #include struct Provider { QString entryId; QString entryProviderId; }; - +class QSortFilterProxyModel; namespace KNSCore { class DownloadManager; } class ProviderPage : public Page { Q_OBJECT public: explicit ProviderPage(KAssistantDialog *parent = nullptr); void leavePageNext() override; void leavePageNextRequested() override; void leavePageBackRequested() override; QTreeView *treeview() const; Q_SIGNALS: void ghnsNotWanted(); public Q_SLOTS: void startFetchingData(); private: void fillModel(const KNSCore::EntryInternal::List &); void selectionChanged(); void providerStatusChanged(const KNSCore::EntryInternal &); + void slotTextChanged(const QString &str); void findDesktopAndSetAssistant(const QStringList &list); Ui::ProviderPage ui; QStandardItemModel *m_model = nullptr; QStandardItem *m_fetchItem = nullptr; KNSCore::DownloadManager *m_downloadManager = nullptr; + QSortFilterProxyModel *mProxy; KNSCore::EntryInternal::List m_providerEntries; Provider m_wantedProvider; bool m_newPageWanted; bool m_newPageReady; }; #endif diff --git a/src/typepage.cpp b/src/typepage.cpp index 17add85..f5f29ba 100644 --- a/src/typepage.cpp +++ b/src/typepage.cpp @@ -1,133 +1,142 @@ /* Copyright (c) 2009 Volker Krause This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This library 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 Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #include "typepage.h" #include "accountwizard_debug.h" #include #include #include +#include #include #include #include #include "global.h" #include #include TypePage::TypePage(KAssistantDialog *parent) : Page(parent) , m_model(new QStandardItemModel(this)) { ui.setupUi(this); #ifdef ACCOUNTWIZARD_NO_GHNS ui.ghnsButton->hide(); #endif - QSortFilterProxyModel *proxy = new QSortFilterProxyModel(this); - proxy->setSourceModel(m_model); - ui.listView->setModel(proxy); - ui.searchLine->setProxy(proxy); + mProxy = new QSortFilterProxyModel(this); + mProxy->setSourceModel(m_model); + mProxy->setFilterKeyColumn(-1); + mProxy->setFilterCaseSensitivity(Qt::CaseInsensitive); + + ui.listView->setModel(mProxy); + connect(ui.searchLine, &QLineEdit::textChanged, this, &TypePage::slotTextChanged); QStringList list; const QStringList dirs = QStandardPaths::locateAll(QStandardPaths::GenericDataLocation, QStringLiteral("akonadi/accountwizard/"), QStandardPaths::LocateDirectory); for (const QString &dir : dirs) { const QStringList directories = QDir(dir).entryList(QDir::AllDirs); for (const QString &directory : directories) { const QString fullPath = dir + QLatin1Char('/') + directory; const QStringList fileNames = QDir(fullPath).entryList(QStringList() << QStringLiteral("*.desktop")); list.reserve(fileNames.count()); for (const QString &file : fileNames) { list.append(fullPath + QLatin1Char('/') + file); } } } const QStringList filter = Global::typeFilter(); foreach (const QString &entry, list) { KDesktopFile f(entry); qCDebug(ACCOUNTWIZARD_LOG) << entry << f.readName(); const KConfig configWizard(entry); KConfigGroup grp(&configWizard, "Wizard"); const QStringList lstType = grp.readEntry("Type", QStringList()); if (lstType.isEmpty()) { qCDebug(ACCOUNTWIZARD_LOG) << QStringLiteral(" %1 doesn't contains specific type").arg(f.readName()); } if (!filter.isEmpty()) { // stolen from agentfilterproxymodel bool found = false; for (const QString &mimeType : lstType) { if (filter.contains(mimeType)) { found = true; break; } else { for (const QString &type : filter) { QMimeDatabase db; QMimeType typePtr = db.mimeTypeForName(type); if (typePtr.isValid() && typePtr.inherits(mimeType)) { found = true; break; } } } if (found) { break; } } if (!found) { continue; } } QStandardItem *item = new QStandardItem(f.readName()); item->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled); item->setData(entry, Qt::UserRole); if (!f.readIcon().isEmpty()) { item->setData(QIcon::fromTheme(f.readIcon()), Qt::DecorationRole); } item->setData(f.readComment(), Qt::ToolTipRole); m_model->appendRow(item); } connect(ui.listView->selectionModel(), &QItemSelectionModel::selectionChanged, this, &TypePage::selectionChanged); connect(ui.ghnsButton, &QPushButton::clicked, this, &TypePage::ghnsWanted); } +void TypePage::slotTextChanged(const QString &text) +{ + mProxy->setFilterFixedString(text); +} + void TypePage::selectionChanged() { if (ui.listView->selectionModel()->hasSelection()) { setValid(true); } else { setValid(false); } } void TypePage::leavePageNext() { if (!ui.listView->selectionModel()->hasSelection()) { return; } const QModelIndex index = ui.listView->selectionModel()->selectedIndexes().at(0); Global::setAssistant(index.data(Qt::UserRole).toString()); } QTreeView *TypePage::treeview() const { return ui.listView; } diff --git a/src/typepage.h b/src/typepage.h index e026f9f..3263f6b 100644 --- a/src/typepage.h +++ b/src/typepage.h @@ -1,47 +1,49 @@ /* Copyright (c) 2009 Volker Krause This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This library 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 Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #ifndef TYPEPAGE_H #define TYPEPAGE_H #include "page.h" #include #include "ui_typepage.h" - +class QSortFilterProxyModel; class TypePage : public Page { Q_OBJECT public: explicit TypePage(KAssistantDialog *parent = nullptr); void leavePageNext() override; QTreeView *treeview() const; Q_SIGNALS: void ghnsWanted(); private: void selectionChanged(); + void slotTextChanged(const QString &text); Ui::TypePage ui; QStandardItemModel *m_model = nullptr; + QSortFilterProxyModel *mProxy = nullptr; }; #endif diff --git a/src/ui/providerpage.ui b/src/ui/providerpage.ui index 4397624..ae119c8 100644 --- a/src/ui/providerpage.ui +++ b/src/ui/providerpage.ui @@ -1,60 +1,57 @@ ProviderPage 0 0 400 172 Select your provider from the list below or click back if your provider is not listed true - + + + true + + false true true true true true - - - KFilterProxySearchLine - QWidget -
kfilterproxysearchline.h
-
-
diff --git a/src/ui/typepage.ui b/src/ui/typepage.ui index 3358671..f86f575 100644 --- a/src/ui/typepage.ui +++ b/src/ui/typepage.ui @@ -1,84 +1,78 @@ TypePage 0 0 400 - 151 + 197 Select which kind of account you want to create: - + + + true + + false true true true true true - - true - Qt::Horizontal 40 20 Check for more on Internet - - - KFilterProxySearchLine - QWidget -
kfilterproxysearchline.h
-
-