Beispiel #1
0
	DeclarativeWindow::DeclarativeWindow (const QUrl& url, QVariantMap params,
			const QPoint& orig, ViewManager *viewMgr, ICoreProxy_ptr proxy, QWidget *parent)
	: QDeclarativeView (parent)
	{
		new Util::AutoResizeMixin (orig, [viewMgr] () { return viewMgr->GetFreeCoords (); }, this);

		if (!params.take ("keepOnFocusLeave").toBool ())
			new Util::UnhoverDeleteMixin (this, SLOT (beforeDelete ()));

		setStyleSheet ("background: transparent");
		setWindowFlags (Qt::Tool | Qt::FramelessWindowHint);
		setAttribute (Qt::WA_TranslucentBackground);

		for (const auto& cand : Util::GetPathCandidates (Util::SysPath::QML, ""))
			engine ()->addImportPath (cand);

		rootContext ()->setContextProperty ("colorProxy",
				new Util::ColorThemeProxy (proxy->GetColorThemeManager (), this));
		for (const auto& key : params.keys ())
			rootContext ()->setContextProperty (key, params [key]);
		engine ()->addImageProvider ("ThemeIcons", new Util::ThemeImageProvider (proxy));
		setSource (url);

		connect (rootObject (),
				SIGNAL (closeRequested ()),
				this,
				SLOT (deleteLater ()));
	}
Beispiel #2
0
	void Item::Execute (ICoreProxy_ptr proxy) const
	{
		auto command = GetCommand ();

		if (GetType () == Type::Application)
		{
			command.remove ("%c");
			command.remove ("%f");
			command.remove ("%F");
			command.remove ("%u");
			command.remove ("%U");
			command.remove ("%i");
			auto items = command.split (' ', QString::SkipEmptyParts);
			auto removePred = [] (const QString& str)
				{ return str.size () == 2 && str.at (0) == '%'; };
			items.erase (std::remove_if (items.begin (), items.end (), removePred),
					items.end ());
			if (items.isEmpty ())
				return;

			QProcess::startDetached (items.at (0), items.mid (1), GetWorkingDirectory ());
		}
		else if (GetType () == Type::URL)
		{
			const auto& e = Util::MakeEntity (QUrl (command),
					QString (),
					FromUserInitiated | OnlyHandle);
			proxy->GetEntityManager ()->HandleEntity (e);
		}
		else
		{
			qWarning () << Q_FUNC_INFO
					<< "don't know how to execute this type of app";
		}
	}
Beispiel #3
0
	void DeadLyRicS::Init (ICoreProxy_ptr proxy)
	{
		Util::InstallTranslator ("deadlyrics");

		Proxy_ = proxy;

		Searchers_ << std::make_shared<HascirylSearcher> (proxy->GetNetworkAccessManager ());
	}
Beispiel #4
0
	void SavePassword (const QString& password, const QString& key,
			const ICoreProxy_ptr& proxy)
	{
		const auto& plugins = proxy->GetPluginsManager ()->GetAllCastableTo<IPersistentStoragePlugin*> ();
		for (const auto plugin : plugins)
			if (const auto& storage = plugin->RequestStorage ())
				storage->Set (key.toUtf8 (), password);
	}
Beispiel #5
0
	void Plugin::Init (ICoreProxy_ptr proxy)
	{
		Util::InstallTranslator ("azoth_lastseen");

		qRegisterMetaType<LastHash_t> ("LeechCraft::Azoth::LastSeen::LastHash_t");
		qRegisterMetaTypeStreamOperators<LastHash_t> ("LeechCraft::Azoth::LastSeen::LastHash_t");

		Storage_ = std::make_shared<OnDiskStorage> ();

		Migrate (proxy->GetPluginsManager ());
	}
Beispiel #6
0
			void Plugin::Init (ICoreProxy_ptr proxy)
			{
				Translator_.reset (Util::InstallTranslator ("tabpp"));

				XmlSettingsDialog_.reset (new LeechCraft::Util::XmlSettingsDialog ());
				XmlSettingsDialog_->RegisterObject (&XmlSettingsManager::Instance (),
						"tabppsettings.xml");

				Core::Instance ().SetProxy (proxy);

				Dock_ = new TabPPWidget ("Tab++", proxy->GetMainWindow ());
			}
Beispiel #7
0
	ViewManager::ViewManager (ICoreProxy_ptr proxy, Util::ShortcutManager *shortcutMgr, QMainWindow *window, QObject *parent)
	: QObject (parent)
	, Proxy_ (proxy)
	, ViewItemsModel_ (new ViewItemsModel (this))
	, View_ (new SBView)
	, Toolbar_ (new QToolBar (tr ("SB2 panel")))
	, Window_ (window)
	, IsDesktopMode_ (qApp->arguments ().contains ("--desktop"))
	, OnloadWindowIndex_ (GetWindowIndex ())
	, SettingsManager_ (new ViewSettingsManager (this))
	, GeomManager_ (new ViewGeometryManager (this))
	{
		const auto& file = Util::GetSysPath (Util::SysPath::QML, "sb2", "SideView.qml");
		if (file.isEmpty ())
		{
			qWarning () << Q_FUNC_INFO
					<< "file not found";
			return;
		}

		new ViewPropsManager (this, SettingsManager_, this);

		for (const auto& cand : Util::GetPathCandidates (Util::SysPath::QML, ""))
			View_->engine ()->addImportPath (cand);

		View_->rootContext ()->setContextProperty ("itemsModel", ViewItemsModel_);
		View_->rootContext ()->setContextProperty ("quarkProxy", new QuarkProxy (this, proxy, this));
		View_->rootContext ()->setContextProperty ("colorProxy",
				new Util::ColorThemeProxy (proxy->GetColorThemeManager (), this));
		View_->rootContext ()->setContextProperty ("SB2_settingsModeTooltip", tr ("Settings mode"));
		View_->rootContext ()->setContextProperty ("SB2_quarkOrderTooltip", tr ("Quarks order"));
		View_->rootContext ()->setContextProperty ("SB2_addQuarkTooltip", tr ("Add quark"));
		View_->rootContext ()->setContextProperty ("SB2_showPanelSettingsTooltip", tr ("Show panel settings"));
		View_->rootContext ()->setContextProperty ("quarkContext", "panel_" + QString::number (GetWindowIndex ()));
		View_->engine ()->addImageProvider (ImageProviderID, new Util::ThemeImageProvider (proxy));

		Toolbar_->addWidget (View_);
		View_->setVisible (true);

		GeomManager_->Manage ();

		View_->setSource (QUrl::fromLocalFile (file));

		LoadRemovedList ();
		LoadQuarkOrder ();

		auto toggleAct = Toolbar_->toggleViewAction ();
		toggleAct->setProperty ("ActionIcon", "layer-visible-on");
		toggleAct->setShortcut (QString ("Ctrl+J,S"));
		shortcutMgr->RegisterAction ("TogglePanel", toggleAct);

		window->addAction (toggleAct);
	}
Beispiel #8
0
		void PerformPaste (ICLEntry *other, const QString& text,
				const ICoreProxy_ptr& proxy, const IUserChoiceHandler_ptr& handler,
				OkF okCont, CancelF cancelCont)
		{
			QSettings settings (QCoreApplication::organizationName (),
					QCoreApplication::applicationName () + "_Azoth_Autopaste");
			settings.beginGroup ("SavedChoices");
			settings.beginGroup (other->GetEntryID ());
			const auto guard = Util::MakeScopeGuard ([&settings]
					{
						settings.endGroup ();
						settings.endGroup ();
					});

			if (!handler->ShouldAsk (settings))
				return;

			PasteDialog dia;

			dia.SetCreatorName (settings.value ("Service").toString ());
			dia.SetHighlight (static_cast<Highlight> (settings.value ("Highlight").toInt ()));

			dia.exec ();

			switch (dia.GetChoice ())
			{
			case PasteDialog::Cancel:
				cancelCont ();
				break;
			case PasteDialog::No:
				handler->Rejected (settings);
				break;
			case PasteDialog::Yes:
			{
				auto service = dia.GetCreator () (other->GetQObject (), proxy);
				service->Paste ({ proxy->GetNetworkAccessManager (), text, dia.GetHighlight () });
				okCont ();

				handler->Accepted (settings);

				settings.setValue ("Service", dia.GetCreatorName ());
				settings.setValue ("Highlight", static_cast<int> (dia.GetHighlight ()));
				break;
			}
			}
		}
Beispiel #9
0
	TabUnhideListView::TabUnhideListView (const QList<TabClassInfo>& tcs, ICoreProxy_ptr proxy, QWidget *parent)
	: QDeclarativeView (parent)
	, Model_ (new UnhideListModel (this))
	{
		new Util::UnhoverDeleteMixin (this);

		const auto& file = Util::GetSysPath (Util::SysPath::QML, "sb2", "TabUnhideListView.qml");
		if (file.isEmpty ())
		{
			qWarning () << Q_FUNC_INFO
					<< "file not found";
			deleteLater ();
			return;
		}

		setStyleSheet ("background: transparent");
		setWindowFlags (Qt::ToolTip);
		setAttribute (Qt::WA_TranslucentBackground);

		rootContext ()->setContextProperty ("unhideListModel", Model_);
		rootContext ()->setContextProperty ("colorProxy",
				new Util::ColorThemeProxy (proxy->GetColorThemeManager (), this));
		engine ()->addImageProvider ("ThemeIcons", new ThemeImageProvider (proxy));
		setSource (QUrl::fromLocalFile (file));

		for (const auto& tc : tcs)
		{
			auto item = new QStandardItem;
			item->setData (tc.TabClass_, UnhideListModel::Roles::TabClass);
			item->setData (tc.VisibleName_, UnhideListModel::Roles::TabName);
			item->setData (tc.Description_, UnhideListModel::Roles::TabDescription);
			item->setData (Util::GetAsBase64Src (tc.Icon_.pixmap (32, 32).toImage ()),
					UnhideListModel::Roles::TabIcon);
			Model_->appendRow (item);
		}

		connect (rootObject (),
				SIGNAL (closeRequested ()),
				this,
				SLOT (deleteLater ()));
		connect (rootObject (),
				SIGNAL (tabUnhideRequested (QString)),
				this,
				SLOT (unhide (QString)),
				Qt::QueuedConnection);
	}
Beispiel #10
0
	void Plugin::Init (ICoreProxy_ptr proxy)
	{
		Util::InstallTranslator ("lastfmscrobble");

		Proxy_ = proxy;
		XmlSettingsDialog_.reset (new Util::XmlSettingsDialog ());
		XmlSettingsDialog_->RegisterObject (&XmlSettingsManager::Instance (),
				"lastfmscrobblesettings.xml");

		Auth_ = new Authenticator (proxy->GetNetworkAccessManager (), proxy, this);

		LFSubmitter_ = new LastFMSubmitter (Proxy_->GetNetworkAccessManager (), this);

		connect (Auth_,
				SIGNAL (authenticated ()),
				LFSubmitter_,
				SLOT (handleAuthenticated ()));

		RadioRoot_ = new QStandardItem ("Last.FM");
		RadioRoot_->setEditable (false);
		RadioRoot_->setIcon (QIcon (":/resources/images/lastfm.png"));
		auto addPredefined = [this] (const QString& name, const QString& id, const QIcon& icon) -> QStandardItem*
		{
			auto item = new QStandardItem (name);
			item->setData (Media::RadioType::Predefined, Media::RadioItemRole::ItemType);
			item->setData (id, Media::RadioItemRole::RadioID);
			item->setEditable (false);
			item->setIcon (icon);
			RadioRoot_->appendRow (item);
			return item;
		};
		addPredefined (tr ("Library"), "library", QIcon (":/resources/images/personal.png"));
		addPredefined (tr ("Recommendations"), "recommendations", QIcon (":/resources/images/recs.png"));
		addPredefined (tr ("Loved"), "loved", QIcon (":/resources/images/loved.png"));
		addPredefined (tr ("Neighbourhood"), "neighbourhood", QIcon (":/resources/images/neighbours.png"));

		auto similarItem = addPredefined (tr ("Similar artists"),
				QString (), QIcon (":/resources/images/radio.png"));
		similarItem->setData (Media::RadioType::SimilarArtists, Media::RadioItemRole::ItemType);
		auto globalItem = addPredefined (tr ("Global tag"),
				QString (), QIcon (":/resources/images/tag.png"));
		globalItem->setData (Media::RadioType::GlobalTag, Media::RadioItemRole::ItemType);;

		RadioModel_ = new QStandardItemModel;
		RadioModel_->appendRow (RadioRoot_);
	}
Beispiel #11
0
	MailListView::MailListView (const ConvInfos_t& infos, ICoreProxy_ptr proxy, QWidget *parent)
	: QQuickWidget (parent)
	, Model_ (new MailListModel (this))
	{
		new Util::UnhoverDeleteMixin (this);

		const auto& file = Util::GetSysPath (Util::SysPath::QML, "gmailnotifier", "MailListView.qml");
		if (file.isEmpty ())
		{
			qWarning () << Q_FUNC_INFO
					<< "file not found";
			deleteLater ();
			return;
		}

		const auto& now = QDateTime::currentDateTime ();
		for (const auto& info : infos)
		{
			auto item = new QStandardItem;
			item->setData (info.Title_, MailListModel::Roles::Subject);
			item->setData (info.AuthorEmail_, MailListModel::Roles::AuthorEmail);
			item->setData (info.AuthorName_, MailListModel::Roles::AuthorName);
			item->setData (info.Summary_, MailListModel::Roles::Summary);

			QString dateString;
			if (info.Modified_.secsTo (now) < 12 * 60 * 60)
				dateString = info.Modified_.time ().toString ("hh:mm");
			else if (now.date ().day () == info.Modified_.date ().day () - 1)
				dateString = tr ("Yesterday, %1").arg (info.Modified_.time ().toString ());
			else if (now.date ().year () == info.Modified_.date ().year ())
				dateString = info.Modified_.date ().toString ("d MMM");
			else
				dateString = info.Modified_.date ().toString (Qt::DefaultLocaleShortDate);
			item->setData (dateString, MailListModel::Roles::ModifiedDate);
			Model_->appendRow (item);
		}

		setStyleSheet ("background: transparent");
		setWindowFlags (Qt::ToolTip);
		setAttribute (Qt::WA_TranslucentBackground);

		rootContext ()->setContextProperty ("mailListModel", Model_);
		rootContext ()->setContextProperty ("colorProxy",
				new Util::ColorThemeProxy (proxy->GetColorThemeManager (), this));
		setSource (QUrl::fromLocalFile (file));
	}
Beispiel #12
0
	QVariant GetPersistentData (const QByteArray& key,
			const ICoreProxy_ptr& proxy)
	{
		const auto& plugins = proxy->GetPluginsManager ()->
				GetAllCastableTo<IPersistentStoragePlugin*> ();
		for (const auto plug : plugins)
		{
			const auto& storage = plug->RequestStorage ();
			if (!storage)
				continue;

			const auto& value = storage->Get (key);
			if (!value.isNull ())
				return value;
		}
		return {};
	}
Beispiel #13
0
	void Plugin::Init (ICoreProxy_ptr proxy)
	{
		Util::InstallTranslator ("vrooby");

		TrayView_ = new TrayView (proxy);
		new Util::UnhoverDeleteMixin (TrayView_, SLOT (hide ()));

		QList<std::shared_ptr<DevBackend>> candidates;

#ifdef ENABLE_UDISKS2
		candidates << std::make_shared<UDisks2::Backend> (proxy);
#endif
#ifdef ENABLE_UDISKS
		candidates << std::make_shared<UDisks::Backend> (proxy);
#endif

		QStringList allBackends;
		for (const auto& cand : candidates)
		{
			allBackends << cand->GetBackendName ();
			if (cand->IsAvailable ())
			{
				qDebug () << Q_FUNC_INFO
						<< "selecting"
						<< cand->GetBackendName ();
				Backend_ = cand;
				break;
			}
		}

		if (!Backend_)
		{
			const auto& e = Util::MakeNotification ("Vrooby",
					tr ("No backends are available, tried the following: %1.")
						.arg (allBackends.join ("; ")),
					Priority::Critical);
			Util::ExecuteLater ([e, proxy] { proxy->GetEntityManager ()->HandleEntity (e); });
		}
	}
	BitcheesePending::BitcheesePending (const QString& filename, const ICoreProxy_ptr& proxy, QObject *parent)
	: PendingUploadBase { filename, proxy, parent }
	{
		const auto nam = proxy->GetNetworkAccessManager ();

		QNetworkRequest req { QUrl { "http://dump.bitcheese.net/upload-file" } };
		req.setRawHeader ("Referer", "http://dump.bitcheese.net/");

		const auto reply = nam->post (req, MakeStandardMultipart ());
		connect (reply,
				SIGNAL (finished ()),
				this,
				SLOT (handleFinished ()));
		connect (reply,
				SIGNAL (error (QNetworkReply::NetworkError)),
				this,
				SLOT (handleError ()));

		connect (reply,
				SIGNAL (uploadProgress (qint64, qint64)),
				this,
				SLOT (handleUploadProgress (qint64, qint64)));
	}
Beispiel #15
0
	Checker::Checker (CheckModel *model,
			const QList<Media::ReleaseInfo::Type>& types,
			const ILMPProxy_ptr& lmpProxy,
			const ICoreProxy_ptr& coreProxy,
			QObject *parent)
	: QObject { parent }
	, Model_ { model }
	, Provider_ { coreProxy->GetPluginsManager ()->
				GetAllCastableTo<Media::IDiscographyProvider*> ().value (0) }
	, LmpProxy_ { lmpProxy }
	, Types_ { types }
	, Artists_ { Model_->GetSelectedArtists () }
	{
		if (!Provider_)
		{
			qWarning () << Q_FUNC_INFO
					<< "no providers :(";
			deleteLater ();
			return;
		}

		rotateQueue ();
	}
	UnhideListViewBase::UnhideListViewBase (ICoreProxy_ptr proxy, QWidget *parent)
	: QDeclarativeView (parent)
	, Model_ (new UnhideListModel (this))
	{
		new UnhoverDeleteMixin (this);

		const auto& file = GetSysPath (SysPath::QML, "common", "UnhideListView.qml");
		if (file.isEmpty ())
		{
			qWarning () << Q_FUNC_INFO
					<< "file not found";
			deleteLater ();
			return;
		}

		setStyleSheet ("background: transparent");
		setWindowFlags (Qt::ToolTip);
		setAttribute (Qt::WA_TranslucentBackground);

		for (const auto& cand : GetPathCandidates (SysPath::QML, ""))
			engine ()->addImportPath (cand);

		rootContext ()->setContextProperty ("unhideListModel", Model_);
		rootContext ()->setContextProperty ("colorProxy",
				new Util::ColorThemeProxy (proxy->GetColorThemeManager (), this));
		engine ()->addImageProvider ("ThemeIcons", new Util::ThemeImageProvider (proxy));
		setSource (QUrl::fromLocalFile (file));

		connect (rootObject (),
				SIGNAL (closeRequested ()),
				this,
				SLOT (deleteLater ()));
		connect (rootObject (),
				SIGNAL (itemUnhideRequested (QString)),
				this,
				SIGNAL (itemUnhideRequested (QString)));
	}
	ClearLineEditAddon::ClearLineEditAddon (ICoreProxy_ptr proxy, QLineEdit *edit)
	: QObject (edit)
	, Button_ (new QToolButton (edit))
	, Edit_ (edit)
	{
		const bool isRtl = QApplication::layoutDirection () == Qt::RightToLeft;
		const auto& icon = proxy->GetIcon (isRtl ?
				"edit-clear-locationbar-ltr" :
				"edit-clear-locationbar-rtl");

		Button_->setIconSize (QSize (16, 16));
		Button_->setIcon (icon);
		Button_->setCursor (Qt::ArrowCursor);
		Button_->setStyleSheet ("QToolButton { border: none; padding: 0px; }");
		Button_->hide ();

		connect (Button_,
				SIGNAL (clicked ()),
				edit,
				SLOT (clear ()));
		connect (edit,
				SIGNAL (textChanged (QString)),
				this,
				SLOT (updateButton (QString)));

		const int frameWidth = edit->style ()->pixelMetric (QStyle::PM_DefaultFrameWidth);
		edit->setStyleSheet (QString ("QLineEdit { padding-right: %1px; }")
					.arg (Button_->sizeHint ().width () + frameWidth + 1));
		const auto msz = edit->minimumSizeHint ();
		edit->setMinimumSize (qMax (msz.width (), Button_->sizeHint ().height () + frameWidth * 2 + 2),
						qMax (msz.height(), Button_->sizeHint ().height () + frameWidth * 2 + 2));

		UpdatePos ();

		edit->installEventFilter (this);
	}
Beispiel #18
0
	void Core::SetProxy (ICoreProxy_ptr proxy)
	{
		Proxy_ = proxy;
		NetworkAccessManager_ = proxy->GetNetworkAccessManager ();
		ShortcutProxy_ = proxy->GetShortcutProxy ();
	}
Beispiel #19
0
	Poster::Poster (HostingService service,
			const QByteArray& data,
			const QString& format,
			ICoreProxy_ptr proxy,
			QStandardItemModel *reprModel,
			QObject *parent)
	: QObject (parent)
	, Worker_ (MakeWorker (service))
	, Proxy_ (proxy)
	{
		Promise_.reportStarted ();

		const QList<QStandardItem*> reprRow
		{
			new QStandardItem { tr ("Image upload") },
			new QStandardItem { tr ("Uploading...") },
			new QStandardItem
		};
		for (const auto item : reprRow)
		{
			item->setEditable (false);
			item->setData (QVariant::fromValue<JobHolderRow> (JobHolderRow::ProcessProgress),
					CustomDataRoles::RoleJobHolderRow);
		}
		reprModel->appendRow (reprRow);

		auto setUploadProgress = [reprRow] (qint64 done, qint64 total)
		{
			Util::SetJobHolderProgress (reprRow, done, total,
					tr ("%1 of %2")
							.arg (Util::MakePrettySize (done))
							.arg (Util::MakePrettySize (total)));
		};
		setUploadProgress (0, data.size ());

		const auto reply = Worker_->Post (data, format, proxy->GetNetworkAccessManager ());
		connect (reply,
				&QNetworkReply::uploadProgress,
				this,
				setUploadProgress);

		Util::HandleReplySeq<Util::ErrorInfo<Util::ReplyError>, Util::ResultInfo<Util::ReplyWithHeaders>> (reply, this) >>
				Util::Visitor
				{
					[this, url = reply->request ().url ()] (Util::ReplyError reply)
					{
						Util::ReportFutureResult (Promise_,
								NetworkRequestError
								{
									url,
									reply.Error_,
									!reply.HttpStatusCode_.isNull () && reply.HttpStatusCode_.canConvert<int> () ?
											std::optional<int> { reply.HttpStatusCode_.toInt () } :
											std::optional<int> {},
									reply.ErrorString_
								});
					},
					[this] (Util::ReplyWithHeaders reply)
					{
						Util::ReportFutureResult (Promise_, Worker_->GetLink (reply.Data_, reply.Headers_));
					}
				}.Finally ([this, reprModel, reprRow]
						{
							deleteLater ();
							reprModel->removeRow (reprRow.first ()->row ());
						});
	}
Beispiel #20
0
	CheckModel::CheckModel (const Collection::Artists_t& artists,
			const ICoreProxy_ptr& proxy, const ILMPProxy_ptr& lmpProxy, QObject *parent)
	: RoleNamesMixin<QStandardItemModel> { parent }
	, AllArtists_ { artists }
	, Proxy_ { lmpProxy }
	, DefaultAlbumIcon_ { GetIcon (proxy, "media-optical", AASize * 2) }
	, DefaultArtistIcon_ { GetIcon (proxy, "view-media-artist", ArtistSize * 2) }
	, AAProv_ { proxy->GetPluginsManager ()->
				GetAllCastableTo<Media::IAlbumArtProvider*> ().value (0) }
	, BioProv_ { proxy->GetPluginsManager ()->
				GetAllCastableTo<Media::IArtistBioFetcher*> ().value (0) }
	{
		QHash<int, QByteArray> roleNames;
		roleNames [Role::ArtistId] = "artistId";
		roleNames [Role::ArtistName] = "artistName";
		roleNames [Role::ScheduledToCheck] = "scheduled";
		roleNames [Role::IsChecked] = "isChecked";
		roleNames [Role::ArtistImage] = "artistImageUrl";
		roleNames [Role::Releases] = "releases";
		roleNames [Role::MissingCount] = "missingCount";
		roleNames [Role::PresentCount] = "presentCount";
		setRoleNames (roleNames);

		for (const auto& artist : artists)
		{
			if (artist.Name_.contains (" vs. ") ||
					artist.Name_.contains (" with ") ||
					artist.Albums_.isEmpty ())
				continue;

			auto item = new QStandardItem { artist.Name_ };
			item->setData (artist.ID_, Role::ArtistId);
			item->setData (artist.Name_, Role::ArtistName);
			item->setData (true, Role::ScheduledToCheck);
			item->setData (false, Role::IsChecked);
			item->setData (DefaultArtistIcon_, Role::ArtistImage);
			item->setData (0, Role::MissingCount);
			item->setData (artist.Albums_.size (), Role::PresentCount);

			const auto submodel = new ReleasesSubmodel { this };
			item->setData (QVariant::fromValue<QObject*> (submodel), Role::Releases);

			appendRow (item);

			Artist2Submodel_ [artist.ID_] = submodel;
			Artist2Item_ [artist.ID_] = item;

			Scheduled_ << artist.ID_;

			const auto proxy = BioProv_->RequestArtistBio (artist.Name_, false);
			new Util::OneTimeRunner
			{
				[this, artist, item, proxy] () -> void
				{
					if (!Artist2Item_.contains (artist.ID_))
						return;

					const auto& url = proxy->GetArtistBio ().BasicInfo_.LargeImage_;
					item->setData (url, Role::ArtistImage);
				},
				proxy->GetQObject (),
				{
					SIGNAL (ready ()),
					SIGNAL (error ())
				},
				this
			};
		}
	}
Beispiel #21
0
	ConcreteSite::ConcreteSite (const Media::LyricsQuery& query,
			const ConcreteSiteDesc& desc, ICoreProxy_ptr proxy, QObject *parent)
	: QObject (parent)
	, Query_ (query)
	, Desc_ (desc)
	{
		auto replace = [this] (QString str) -> QString
		{
			for (const auto& c : Desc_.Replacements_.keys ())
				str.replace (c, Desc_.Replacements_ [c]);
			return str;
		};

		const auto& artist = replace (query.Artist_.toLower ());
		const auto& album = replace (query.Album_.toLower ());
		const auto& title = replace (query.Title_.toLower ());

		auto urlStr = Desc_.URLTemplate_;
		urlStr.replace ("{artist}", artist);
		urlStr.replace ("{album}", album);
		urlStr.replace ("{title}", title);
		if (!artist.isEmpty ())
			urlStr.replace ("{a}", artist.at (0).toLower ());

		auto cap = [] (QString str) -> QString
		{
			if (!str.isEmpty ())
				str [0] = str [0].toUpper ();
			return str;
		};
		urlStr.replace ("{Artist}", cap (artist));
		urlStr.replace ("{Album}", cap (album));
		urlStr.replace ("{Title}", cap (title));

#ifdef QT_DEBUG
		qDebug () << Q_FUNC_INFO
				<< "requesting"
				<< urlStr
				<< "from"
				<< Desc_.Name_
				<< "for"
				<< artist
				<< album
				<< title;
#endif

		auto nam = proxy->GetNetworkAccessManager ();

		QUrl url { urlStr };
		QNetworkRequest req { url };

		url.setPath ({});
#if QT_VERSION < 0x050000
		url.setQueryItems ({});
#else
		url.setQuery ({});
#endif
		req.setRawHeader ("Referer", url.toString ().toUtf8 ());

		auto reply = nam->get (req);
		connect (reply,
				SIGNAL (finished ()),
				this,
				SLOT (handleReplyFinished ()));
		connect (reply,
				SIGNAL (error (QNetworkReply::NetworkError)),
				this,
				SLOT (handleReplyError ()));
	}