2010-03-24 00:11:46 +01:00
|
|
|
/* This file is part of Clementine.
|
2014-12-17 19:02:21 +01:00
|
|
|
Copyright 2009-2014, David Sansome <me@davidsansome.com>
|
|
|
|
Copyright 2011-2012, 2014, Arnaud Bienner <arnaud.bienner@gmail.com>
|
|
|
|
Copyright 2011, Tyler Rhodes <tyler.s.rhodes@gmail.com>
|
|
|
|
Copyright 2011, Paweł Bara <keirangtp@gmail.com>
|
2014-12-19 00:46:38 +01:00
|
|
|
Copyright 2012-2013, Alan Briolat <alan.briolat@gmail.com>
|
|
|
|
Copyright 2012-2014, John Maguire <john.maguire@gmail.com>
|
2014-12-17 19:02:21 +01:00
|
|
|
Copyright 2014, Maltsev Vlad <shedwardx@gmail.com>
|
|
|
|
Copyright 2014, Chocobozzz <florian.bigard@gmail.com>
|
|
|
|
Copyright 2014, Krzysztof Sobiecki <sobkas@gmail.com>
|
2010-03-24 00:11:46 +01:00
|
|
|
|
|
|
|
Clementine 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 3 of the License, or
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
Clementine 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 Clementine. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
2014-12-18 23:35:21 +01:00
|
|
|
#include "internet/core/internetmodel.h"
|
2012-10-12 14:54:47 +02:00
|
|
|
|
|
|
|
#include <QMimeData>
|
|
|
|
#include <QtDebug>
|
|
|
|
|
2016-11-07 19:22:06 +01:00
|
|
|
#include "core/closure.h"
|
|
|
|
#include "core/logging.h"
|
|
|
|
#include "core/mergedproxymodel.h"
|
2014-12-18 23:35:21 +01:00
|
|
|
#include "internet/core/internetmimedata.h"
|
|
|
|
#include "internet/core/internetservice.h"
|
2016-11-07 19:22:06 +01:00
|
|
|
#include "internet/digitally/digitallyimportedservicebase.h"
|
|
|
|
#include "internet/icecast/icecastservice.h"
|
|
|
|
#include "internet/intergalacticfm/intergalacticfmservice.h"
|
|
|
|
#include "internet/internetradio/savedradio.h"
|
2014-12-18 23:35:21 +01:00
|
|
|
#include "internet/jamendo/jamendoservice.h"
|
|
|
|
#include "internet/magnatune/magnatuneservice.h"
|
2016-11-07 19:22:06 +01:00
|
|
|
#include "internet/podcasts/podcastservice.h"
|
2014-12-18 23:35:21 +01:00
|
|
|
#include "internet/somafm/somafmservice.h"
|
|
|
|
#include "internet/subsonic/subsonicservice.h"
|
2011-11-29 13:57:35 +01:00
|
|
|
#include "smartplaylists/generatormimedata.h"
|
2009-12-26 22:35:45 +01:00
|
|
|
|
2012-07-26 22:23:08 +02:00
|
|
|
#ifdef HAVE_GOOGLE_DRIVE
|
2014-12-18 23:35:21 +01:00
|
|
|
#include "internet/googledrive/googledriveservice.h"
|
2012-07-26 22:23:08 +02:00
|
|
|
#endif
|
2012-11-29 18:19:41 +01:00
|
|
|
#ifdef HAVE_DROPBOX
|
2014-12-18 23:35:21 +01:00
|
|
|
#include "internet/dropbox/dropboxservice.h"
|
2012-11-29 18:19:41 +01:00
|
|
|
#endif
|
2012-12-12 18:34:15 +01:00
|
|
|
#ifdef HAVE_SKYDRIVE
|
2014-12-18 23:35:21 +01:00
|
|
|
#include "internet/skydrive/skydriveservice.h"
|
2012-12-12 18:34:15 +01:00
|
|
|
#endif
|
2013-02-12 13:54:19 +01:00
|
|
|
#ifdef HAVE_BOX
|
2014-12-18 00:39:20 +01:00
|
|
|
#include "internet/box/boxservice.h"
|
2013-02-12 13:54:19 +01:00
|
|
|
#endif
|
2014-06-03 14:33:07 +02:00
|
|
|
#ifdef HAVE_SEAFILE
|
2014-12-18 23:35:21 +01:00
|
|
|
#include "internet/seafile/seafileservice.h"
|
2014-06-03 14:33:07 +02:00
|
|
|
#endif
|
2018-11-29 22:32:12 +01:00
|
|
|
#ifdef HAVE_SPOTIFY
|
|
|
|
#include "internet/spotify/spotifyservice.h"
|
|
|
|
#endif
|
2014-06-03 14:33:07 +02:00
|
|
|
|
2011-11-29 13:57:35 +01:00
|
|
|
using smart_playlists::Generator;
|
|
|
|
using smart_playlists::GeneratorMimeData;
|
|
|
|
using smart_playlists::GeneratorPtr;
|
|
|
|
|
2014-02-06 16:49:49 +01:00
|
|
|
QMap<QString, InternetService*>* InternetModel::sServices = nullptr;
|
2009-12-26 16:13:38 +01:00
|
|
|
|
2014-10-15 20:44:09 +02:00
|
|
|
const char* InternetModel::kSettingsGroup = "InternetModel";
|
|
|
|
|
2012-02-12 14:41:50 +01:00
|
|
|
InternetModel::InternetModel(Application* app, QObject* parent)
|
2014-02-07 16:34:20 +01:00
|
|
|
: QStandardItemModel(parent),
|
|
|
|
app_(app),
|
|
|
|
merged_model_(new MergedProxyModel(this)) {
|
2011-01-02 15:49:55 +01:00
|
|
|
if (!sServices) {
|
2011-07-15 15:27:50 +02:00
|
|
|
sServices = new QMap<QString, InternetService*>;
|
2011-01-02 15:49:55 +01:00
|
|
|
}
|
|
|
|
Q_ASSERT(sServices->isEmpty());
|
2009-12-26 22:35:45 +01:00
|
|
|
|
2010-05-09 17:51:04 +02:00
|
|
|
merged_model_->setSourceModel(this);
|
2009-12-26 16:13:38 +01:00
|
|
|
|
2016-11-07 19:22:06 +01:00
|
|
|
AddService(new ClassicalRadioService(app, this));
|
2012-02-12 14:41:50 +01:00
|
|
|
AddService(new DigitallyImportedService(app, this));
|
|
|
|
AddService(new IcecastService(app, this));
|
|
|
|
AddService(new JamendoService(app, this));
|
2012-08-08 21:31:51 +02:00
|
|
|
AddService(new JazzRadioService(app, this));
|
2012-02-12 14:41:50 +01:00
|
|
|
AddService(new MagnatuneService(app, this));
|
2012-03-05 19:15:45 +01:00
|
|
|
AddService(new PodcastService(app, this));
|
2012-11-18 01:18:51 +01:00
|
|
|
AddService(new RockRadioService(app, this));
|
2012-02-12 14:41:50 +01:00
|
|
|
AddService(new SavedRadio(app, this));
|
2015-01-15 18:48:04 +01:00
|
|
|
AddService(new RadioTunesService(app, this));
|
2012-02-12 14:41:50 +01:00
|
|
|
AddService(new SomaFMService(app, this));
|
2016-02-05 19:29:43 +01:00
|
|
|
AddService(new IntergalacticFMService(app, this));
|
2018-11-29 22:32:12 +01:00
|
|
|
#ifdef HAVE_SPOTIFY
|
2012-02-12 14:41:50 +01:00
|
|
|
AddService(new SpotifyService(app, this));
|
2018-11-29 22:32:12 +01:00
|
|
|
#endif
|
2012-07-28 15:10:42 +02:00
|
|
|
AddService(new SubsonicService(app, this));
|
2014-03-30 07:48:38 +02:00
|
|
|
#ifdef HAVE_BOX
|
|
|
|
AddService(new BoxService(app, this));
|
2012-11-28 16:51:19 +01:00
|
|
|
#endif
|
2012-11-29 18:19:41 +01:00
|
|
|
#ifdef HAVE_DROPBOX
|
|
|
|
AddService(new DropboxService(app, this));
|
|
|
|
#endif
|
2014-03-30 07:48:38 +02:00
|
|
|
#ifdef HAVE_GOOGLE_DRIVE
|
|
|
|
AddService(new GoogleDriveService(app, this));
|
|
|
|
#endif
|
2014-06-04 17:58:28 +02:00
|
|
|
#ifdef HAVE_SEAFILE
|
|
|
|
AddService(new SeafileService(app, this));
|
|
|
|
#endif
|
2012-12-12 18:34:15 +01:00
|
|
|
#ifdef HAVE_SKYDRIVE
|
|
|
|
AddService(new SkydriveService(app, this));
|
|
|
|
#endif
|
2014-03-30 07:48:38 +02:00
|
|
|
|
2014-12-27 00:33:23 +01:00
|
|
|
invisibleRootItem()->sortChildren(0, Qt::AscendingOrder);
|
2014-10-15 20:44:09 +02:00
|
|
|
UpdateServices();
|
2009-12-26 22:35:45 +01:00
|
|
|
}
|
|
|
|
|
2014-02-07 16:34:20 +01:00
|
|
|
void InternetModel::AddService(InternetService* service) {
|
2011-01-09 19:27:41 +01:00
|
|
|
QStandardItem* root = service->CreateRootItem();
|
2011-01-12 21:18:17 +01:00
|
|
|
if (!root) {
|
2014-02-07 16:34:20 +01:00
|
|
|
qLog(Warning) << "Internet service" << service->name()
|
|
|
|
<< "did not return a root item";
|
2011-01-09 19:27:41 +01:00
|
|
|
return;
|
2011-01-12 21:18:17 +01:00
|
|
|
}
|
2011-01-09 19:27:41 +01:00
|
|
|
|
|
|
|
root->setData(Type_Service, Role_Type);
|
|
|
|
root->setData(QVariant::fromValue(service), Role_Service);
|
|
|
|
|
|
|
|
invisibleRootItem()->appendRow(root);
|
2011-07-15 15:27:50 +02:00
|
|
|
qLog(Debug) << "Adding internet service:" << service->name();
|
2011-01-02 15:49:55 +01:00
|
|
|
sServices->insert(service->name(), service);
|
2009-12-26 22:35:45 +01:00
|
|
|
|
2014-10-15 20:44:09 +02:00
|
|
|
ServiceItem service_item;
|
|
|
|
service_item.item = root;
|
|
|
|
service_item.shown = true;
|
|
|
|
|
|
|
|
shown_services_.insert(service, service_item);
|
|
|
|
|
2009-12-26 22:35:45 +01:00
|
|
|
connect(service, SIGNAL(StreamError(QString)), SIGNAL(StreamError(QString)));
|
2014-02-07 16:34:20 +01:00
|
|
|
connect(service, SIGNAL(StreamMetadataFound(QUrl, Song)),
|
|
|
|
SIGNAL(StreamMetadataFound(QUrl, Song)));
|
|
|
|
connect(service, SIGNAL(AddToPlaylistSignal(QMimeData*)),
|
|
|
|
SIGNAL(AddToPlaylist(QMimeData*)));
|
|
|
|
connect(service, SIGNAL(ScrollToIndex(QModelIndex)),
|
|
|
|
SIGNAL(ScrollToIndex(QModelIndex)));
|
2011-01-12 21:18:17 +01:00
|
|
|
connect(service, SIGNAL(destroyed()), SLOT(ServiceDeleted()));
|
2011-07-21 01:03:55 +02:00
|
|
|
|
2014-12-14 14:35:21 +01:00
|
|
|
if (service->has_initial_load_settings()) {
|
|
|
|
service->InitialLoadSettings();
|
2014-12-11 01:25:56 +01:00
|
|
|
} else {
|
|
|
|
service->ReloadSettings();
|
|
|
|
}
|
2011-01-12 21:18:17 +01:00
|
|
|
}
|
|
|
|
|
2011-07-15 15:27:50 +02:00
|
|
|
void InternetModel::RemoveService(InternetService* service) {
|
2014-02-07 16:34:20 +01:00
|
|
|
if (!sServices->contains(service->name())) return;
|
2011-01-12 21:18:17 +01:00
|
|
|
|
|
|
|
// Find and remove the root item that this service created
|
2014-02-07 16:34:20 +01:00
|
|
|
for (int i = 0; i < invisibleRootItem()->rowCount(); ++i) {
|
2011-05-30 16:54:48 +02:00
|
|
|
QStandardItem* item = invisibleRootItem()->child(i);
|
2014-02-07 16:34:20 +01:00
|
|
|
if (!item ||
|
|
|
|
item->data(Role_Service).value<InternetService*>() == service) {
|
2011-01-12 21:18:17 +01:00
|
|
|
invisibleRootItem()->removeRow(i);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Remove the service from the list
|
|
|
|
sServices->remove(service->name());
|
|
|
|
|
2014-10-15 20:44:09 +02:00
|
|
|
// Don't forget to delete from shown_services too
|
|
|
|
shown_services_.remove(service);
|
|
|
|
|
2011-01-12 21:18:17 +01:00
|
|
|
// Disconnect the service
|
|
|
|
disconnect(service, 0, this, 0);
|
|
|
|
}
|
|
|
|
|
2011-07-15 15:27:50 +02:00
|
|
|
void InternetModel::ServiceDeleted() {
|
2011-07-21 01:17:37 +02:00
|
|
|
InternetService* service = qobject_cast<InternetService*>(sender());
|
2014-02-07 16:34:20 +01:00
|
|
|
if (service) RemoveService(service);
|
2009-12-26 22:35:45 +01:00
|
|
|
}
|
|
|
|
|
2011-07-15 15:27:50 +02:00
|
|
|
InternetService* InternetModel::ServiceByName(const QString& name) {
|
2014-02-07 16:34:20 +01:00
|
|
|
if (sServices->contains(name)) return sServices->value(name);
|
2014-02-06 16:49:49 +01:00
|
|
|
return nullptr;
|
2009-12-26 16:13:38 +01:00
|
|
|
}
|
|
|
|
|
2014-03-27 18:55:58 +01:00
|
|
|
InternetService* InternetModel::ServiceForItem(
|
|
|
|
const QStandardItem* item) const {
|
2011-01-09 19:27:41 +01:00
|
|
|
return ServiceForIndex(indexFromItem(item));
|
2009-12-26 16:13:38 +01:00
|
|
|
}
|
|
|
|
|
2014-03-27 18:55:58 +01:00
|
|
|
InternetService* InternetModel::ServiceForIndex(
|
|
|
|
const QModelIndex& index) const {
|
2011-01-09 19:27:41 +01:00
|
|
|
QModelIndex current_index = index;
|
|
|
|
while (current_index.isValid()) {
|
2014-02-07 16:34:20 +01:00
|
|
|
InternetService* service =
|
|
|
|
current_index.data(Role_Service).value<InternetService*>();
|
2011-01-09 19:27:41 +01:00
|
|
|
if (service) {
|
|
|
|
return service;
|
|
|
|
}
|
|
|
|
current_index = current_index.parent();
|
2009-12-26 16:13:38 +01:00
|
|
|
}
|
2014-02-06 16:49:49 +01:00
|
|
|
return nullptr;
|
2009-12-26 16:13:38 +01:00
|
|
|
}
|
2009-12-26 22:35:45 +01:00
|
|
|
|
2011-07-15 15:27:50 +02:00
|
|
|
Qt::ItemFlags InternetModel::flags(const QModelIndex& index) const {
|
2014-02-07 16:34:20 +01:00
|
|
|
Qt::ItemFlags flags =
|
|
|
|
Qt::ItemIsSelectable | Qt::ItemIsEnabled | Qt::ItemIsDropEnabled;
|
2011-10-30 23:59:43 +01:00
|
|
|
if (IsPlayable(index)) {
|
|
|
|
flags |= Qt::ItemIsDragEnabled;
|
|
|
|
}
|
|
|
|
return flags;
|
2009-12-26 22:35:45 +01:00
|
|
|
}
|
|
|
|
|
2011-07-15 15:27:50 +02:00
|
|
|
bool InternetModel::hasChildren(const QModelIndex& parent) const {
|
2014-02-07 16:34:20 +01:00
|
|
|
if (parent.data(Role_CanLazyLoad).toBool()) return true;
|
2011-01-09 19:27:41 +01:00
|
|
|
return QStandardItemModel::hasChildren(parent);
|
|
|
|
}
|
|
|
|
|
2011-07-15 15:27:50 +02:00
|
|
|
int InternetModel::rowCount(const QModelIndex& parent) const {
|
2011-01-09 19:27:41 +01:00
|
|
|
if (parent.data(Role_CanLazyLoad).toBool()) {
|
|
|
|
QStandardItem* item = itemFromIndex(parent);
|
2011-07-15 15:27:50 +02:00
|
|
|
InternetService* service = ServiceForItem(item);
|
2011-01-09 19:27:41 +01:00
|
|
|
if (service) {
|
|
|
|
item->setData(false, Role_CanLazyLoad);
|
|
|
|
service->LazyPopulate(item);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return QStandardItemModel::rowCount(parent);
|
|
|
|
}
|
|
|
|
|
2011-07-15 15:27:50 +02:00
|
|
|
bool InternetModel::IsPlayable(const QModelIndex& index) const {
|
2011-01-09 19:27:41 +01:00
|
|
|
QVariant behaviour = index.data(Role_PlayBehaviour);
|
2014-02-07 16:34:20 +01:00
|
|
|
if (!behaviour.isValid()) return false;
|
2011-04-29 13:24:58 +02:00
|
|
|
|
|
|
|
PlayBehaviour pb = PlayBehaviour(behaviour.toInt());
|
2012-07-29 01:35:05 +02:00
|
|
|
return (pb == PlayBehaviour_MultipleItems || pb == PlayBehaviour_SingleItem ||
|
|
|
|
pb == PlayBehaviour_UseSongLoader);
|
2011-01-09 19:27:41 +01:00
|
|
|
}
|
|
|
|
|
2011-07-15 15:27:50 +02:00
|
|
|
QStringList InternetModel::mimeTypes() const {
|
2009-12-26 22:35:45 +01:00
|
|
|
return QStringList() << "text/uri-list";
|
|
|
|
}
|
|
|
|
|
2011-07-15 15:27:50 +02:00
|
|
|
QMimeData* InternetModel::mimeData(const QModelIndexList& indexes) const {
|
2011-04-29 13:24:58 +02:00
|
|
|
// Special case for when the user double clicked on a special item.
|
2014-06-04 17:58:28 +02:00
|
|
|
if (indexes.count() == 1 &&
|
|
|
|
indexes[0].data(Role_PlayBehaviour).toInt() ==
|
|
|
|
PlayBehaviour_DoubleClickAction) {
|
2014-02-07 16:34:20 +01:00
|
|
|
InternetModel::ServiceForIndex(indexes[0])
|
|
|
|
->ItemDoubleClicked(itemFromIndex(indexes[0]));
|
2014-02-06 16:49:49 +01:00
|
|
|
return nullptr;
|
2011-04-29 13:24:58 +02:00
|
|
|
}
|
|
|
|
|
2011-11-29 13:57:35 +01:00
|
|
|
if (indexes.count() == 1 &&
|
|
|
|
indexes[0].data(Role_Type).toInt() == Type_SmartPlaylist) {
|
2014-02-07 16:34:20 +01:00
|
|
|
GeneratorPtr generator = InternetModel::ServiceForIndex(indexes[0])
|
|
|
|
->CreateGenerator(itemFromIndex(indexes[0]));
|
|
|
|
if (!generator) return nullptr;
|
2011-11-29 13:57:35 +01:00
|
|
|
GeneratorMimeData* data = new GeneratorMimeData(generator);
|
|
|
|
data->setData(LibraryModel::kSmartPlaylistsMimeType, QByteArray());
|
|
|
|
data->name_for_new_playlist_ = this->data(indexes.first()).toString();
|
|
|
|
return data;
|
|
|
|
}
|
|
|
|
|
2009-12-26 22:35:45 +01:00
|
|
|
QList<QUrl> urls;
|
2011-10-14 00:10:18 +02:00
|
|
|
QModelIndexList new_indexes;
|
2009-12-26 22:35:45 +01:00
|
|
|
|
2011-02-16 19:29:35 +01:00
|
|
|
QModelIndex last_valid_index;
|
2014-02-10 14:29:07 +01:00
|
|
|
for (const QModelIndex& index : indexes) {
|
2014-02-07 16:34:20 +01:00
|
|
|
if (!IsPlayable(index)) continue;
|
2009-12-26 22:35:45 +01:00
|
|
|
|
2011-02-16 19:29:35 +01:00
|
|
|
last_valid_index = index;
|
2012-07-29 01:35:05 +02:00
|
|
|
if (index.data(Role_PlayBehaviour).toInt() == PlayBehaviour_MultipleItems) {
|
2011-10-15 18:17:00 +02:00
|
|
|
// Get children
|
2011-10-14 00:10:18 +02:00
|
|
|
int row = 0;
|
|
|
|
int column = 0;
|
|
|
|
QModelIndex child = index.child(row, column);
|
|
|
|
while (child.isValid()) {
|
2013-01-09 22:47:51 +01:00
|
|
|
new_indexes << child;
|
|
|
|
urls << child.data(Role_Url).toUrl();
|
2011-10-14 00:10:18 +02:00
|
|
|
child = index.child(++row, column);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
new_indexes = indexes;
|
2011-10-15 18:17:00 +02:00
|
|
|
urls << index.data(Role_Url).toUrl();
|
2011-10-14 00:10:18 +02:00
|
|
|
}
|
2009-12-26 22:35:45 +01:00
|
|
|
}
|
|
|
|
|
2014-02-07 16:34:20 +01:00
|
|
|
if (urls.isEmpty()) return nullptr;
|
2009-12-26 22:35:45 +01:00
|
|
|
|
2011-07-15 15:27:50 +02:00
|
|
|
InternetMimeData* data = new InternetMimeData(this);
|
2009-12-26 22:35:45 +01:00
|
|
|
data->setUrls(urls);
|
2011-10-14 00:10:18 +02:00
|
|
|
data->indexes = new_indexes;
|
2014-02-07 16:34:20 +01:00
|
|
|
data->name_for_new_playlist_ =
|
|
|
|
InternetModel::ServiceForIndex(last_valid_index)->name();
|
2009-12-26 22:35:45 +01:00
|
|
|
|
|
|
|
return data;
|
|
|
|
}
|
2009-12-29 20:22:02 +01:00
|
|
|
|
2014-02-07 16:34:20 +01:00
|
|
|
bool InternetModel::dropMimeData(const QMimeData* data, Qt::DropAction action,
|
|
|
|
int row, int column,
|
|
|
|
const QModelIndex& parent) {
|
2011-10-30 23:59:43 +01:00
|
|
|
if (action == Qt::IgnoreAction) {
|
|
|
|
return false;
|
|
|
|
}
|
2014-12-03 23:58:09 +01:00
|
|
|
if (parent.data(Role_CanBeModified).toBool() ||
|
|
|
|
parent.parent().data(Role_CanBeModified).toBool()) {
|
2011-10-30 23:59:43 +01:00
|
|
|
InternetModel::ServiceForIndex(parent)->DropMimeData(data, parent);
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2014-02-07 16:34:20 +01:00
|
|
|
void InternetModel::ShowContextMenu(
|
|
|
|
const QModelIndexList& selected_merged_model_indexes,
|
|
|
|
const QModelIndex& current_merged_model_index, const QPoint& global_pos) {
|
2012-03-11 15:44:43 +01:00
|
|
|
current_index_ = merged_model_->mapToSource(current_merged_model_index);
|
|
|
|
|
|
|
|
selected_indexes_.clear();
|
2014-02-10 14:29:07 +01:00
|
|
|
for (const QModelIndex& index : selected_merged_model_indexes) {
|
2012-03-11 15:44:43 +01:00
|
|
|
selected_indexes_ << merged_model_->mapToSource(index);
|
|
|
|
}
|
|
|
|
|
|
|
|
InternetService* service = ServiceForIndex(current_merged_model_index);
|
2014-02-07 16:34:20 +01:00
|
|
|
if (service) service->ShowContextMenu(global_pos);
|
2009-12-30 00:01:07 +01:00
|
|
|
}
|
2010-02-03 19:32:48 +01:00
|
|
|
|
2011-07-15 15:27:50 +02:00
|
|
|
void InternetModel::ReloadSettings() {
|
2014-02-10 14:29:07 +01:00
|
|
|
for (InternetService* service : sServices->values()) {
|
2010-02-03 19:32:48 +01:00
|
|
|
service->ReloadSettings();
|
|
|
|
}
|
|
|
|
}
|
2014-10-15 20:44:09 +02:00
|
|
|
|
|
|
|
void InternetModel::UpdateServices() {
|
|
|
|
QSettings s;
|
|
|
|
s.beginGroup(kSettingsGroup);
|
|
|
|
|
|
|
|
QStringList keys = s.childKeys();
|
|
|
|
|
2014-12-27 01:23:26 +01:00
|
|
|
for (const QString& service_name : keys) {
|
2014-10-15 20:44:09 +02:00
|
|
|
InternetService* internet_service = ServiceByName(service_name);
|
2014-12-27 01:23:26 +01:00
|
|
|
if (internet_service == nullptr) {
|
|
|
|
continue;
|
|
|
|
}
|
2014-10-15 20:44:09 +02:00
|
|
|
bool setting_val = s.value(service_name).toBool();
|
|
|
|
|
|
|
|
// Only update if values are different
|
2019-02-22 18:44:39 +01:00
|
|
|
if (setting_val && !shown_services_[internet_service].shown) {
|
2014-10-15 20:44:09 +02:00
|
|
|
ShowService(internet_service);
|
2019-02-22 18:44:39 +01:00
|
|
|
} else if (!setting_val && shown_services_[internet_service].shown) {
|
2014-10-15 20:44:09 +02:00
|
|
|
HideService(internet_service);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
s.endGroup();
|
2014-12-27 00:33:23 +01:00
|
|
|
}
|
2014-10-15 20:44:09 +02:00
|
|
|
|
2014-12-27 00:33:23 +01:00
|
|
|
int InternetModel::FindItemPosition(const QString& text) {
|
|
|
|
int a = 0;
|
|
|
|
int b = invisibleRootItem()->rowCount() - 1;
|
|
|
|
while (a <= b) {
|
2015-01-15 19:58:20 +01:00
|
|
|
int mid = a + (b - a) / 2;
|
2014-12-27 00:33:23 +01:00
|
|
|
if (invisibleRootItem()->child(mid, 0)->text() < text) {
|
|
|
|
a = mid + 1;
|
|
|
|
} else {
|
|
|
|
b = mid - 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return a;
|
2014-10-15 20:44:09 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void InternetModel::ShowService(InternetService* service) {
|
2019-02-22 18:44:39 +01:00
|
|
|
if (!shown_services_[service].shown) {
|
2014-12-27 00:33:23 +01:00
|
|
|
QStandardItem* item = shown_services_[service].item;
|
|
|
|
int pos = FindItemPosition(item->text());
|
|
|
|
invisibleRootItem()->insertRow(pos, item);
|
2014-10-15 20:44:09 +02:00
|
|
|
shown_services_[service].shown = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void InternetModel::HideService(InternetService* service) {
|
|
|
|
// Find and remove the root item that this service created
|
|
|
|
for (int i = 0; i < invisibleRootItem()->rowCount(); ++i) {
|
|
|
|
QStandardItem* item = invisibleRootItem()->child(i);
|
|
|
|
if (!item ||
|
|
|
|
item->data(Role_Service).value<InternetService*>() == service) {
|
|
|
|
// Don't remove the standarditem behind the row
|
|
|
|
invisibleRootItem()->takeRow(i);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
shown_services_[service].shown = false;
|
|
|
|
}
|