Exemplo n.º 1
0
	void LJBloggingPlatform::handleAddLJUser ()
	{
		auto rootWM = Core::Instance ().GetCoreProxy ()->GetRootWindowsManager ();
		QString name = QInputDialog::getText (rootWM->GetPreferredWindow (),
				tr ("Add LJ User"),
				tr ("Enter LJ user name:"));
		if (name.isEmpty ())
			return;

		emit insertTag (QString ("<lj user=\"%1\" />").arg (name));
	}
Exemplo n.º 2
0
	void CSTP::handleFileExists (boost::logic::tribool *remove)
	{
		auto rootWM = Core::Instance ().GetCoreProxy ()->GetRootWindowsManager ();
		auto userReply = QMessageBox::warning (rootWM->GetPreferredWindow (),
				tr ("File exists"),
				tr ("File %1 already exists, continue download?"),
				QMessageBox::Yes | QMessageBox::No | QMessageBox::Cancel);
		if (userReply == QMessageBox::Yes)
			*remove = false;
		else if (userReply == QMessageBox::No)
			*remove = true;
		else
			*remove = boost::logic::indeterminate;
	}
Exemplo n.º 3
0
	void TrackersChanger::on_ButtonRemove__released ()
	{
		QTreeWidgetItem *current = Ui_.Trackers_->currentItem ();
		if (!current)
			return;

		auto rootWM = Core::Instance ()->GetProxy ()->GetRootWindowsManager ();
		if (QMessageBox::question (rootWM->GetPreferredWindow (),
					tr ("Confirm tracker removal"),
					tr ("Are you sure you want to remove the "
						"following tracker:<br />%1")
						.arg (current->text (0)),
					QMessageBox::Yes | QMessageBox::No) == QMessageBox::Yes)
			delete current;
	}
Exemplo n.º 4
0
			void TorrentMaker::Start (NewTorrentParams params)
			{
				QString filename = params.Output_;
				if (!filename.endsWith (".torrent"))
					filename.append (".torrent");
				QFile file (filename);
				if (!file.open (QIODevice::WriteOnly | QIODevice::Truncate))
				{
					emit error (tr ("Could not open file %1 for write!").arg (filename));
					return;
				}

#if BOOST_FILESYSTEM_VERSION == 2
				boost::filesystem::path::default_name_check (boost::filesystem::no_check);
#endif

				libtorrent::file_storage fs;
#if LIBTORRENT_VERSION_NUM >= 1600
				const auto& fullPath = std::string (params.Path_.toUtf8 ().constData ());
#else
				const auto& fullPath = boost::filesystem::complete (params.Path_.toUtf8 ().constData ());
#endif
				libtorrent::add_files (fs, fullPath, FileFilter);
				libtorrent::create_torrent ct (fs, params.PieceSize_);

				ct.set_creator (qPrintable (QString ("LeechCraft BitTorrent %1")
							.arg (Core::Instance ()->GetProxy ()->GetVersion ())));
				if (!params.Comment_.isEmpty ())
					ct.set_comment (params.Comment_.toUtf8 ());
				for (int i = 0; i < params.URLSeeds_.size (); ++i)
					ct.add_url_seed (params.URLSeeds_.at (0).toStdString ());
				ct.set_priv (!params.DHTEnabled_);

				if (params.DHTEnabled_)
					for (int i = 0; i < params.DHTNodes_.size (); ++i)
					{
						QStringList splitted = params.DHTNodes_.at (i).split (":");
						ct.add_node (std::pair<std::string, int> (splitted [0].trimmed ().toStdString (),
									splitted [1].trimmed ().toInt ()));
					}

				ct.add_tracker (params.AnnounceURL_.toStdString ());

				std::unique_ptr<QProgressDialog> pd (new QProgressDialog ());
				pd->setWindowTitle (tr ("Hashing torrent..."));
				pd->setMaximum (ct.num_pieces ());

				boost::system::error_code hashesError;
				libtorrent::set_piece_hashes (ct,
#if LIBTORRENT_VERSION_NUM >= 1600
						fullPath,
#else
						fullPath.branch_path (),
#endif
						[this, &pd] (int i) { UpdateProgress (i, pd.get ()); },
						hashesError);
				if (hashesError)
				{
					QString message = QString::fromUtf8 (hashesError.message ().c_str ());
					libtorrent::file_entry entry = fs.at (hashesError.value ());
					qWarning () << Q_FUNC_INFO
						<< "while in libtorrent::set_piece_hashes():"
						<< message
						<< hashesError.category ().name ();
					emit error (tr ("Torrent creation failed: %1")
							.arg (message));
					return;
				}

				libtorrent::entry e = ct.generate ();
				std::deque<char> outbuf;
				libtorrent::bencode (std::back_inserter (outbuf), e);

				for (size_t i = 0; i < outbuf.size (); ++i)
					file.write (&outbuf.at (i), 1);
				file.close ();

				auto rootWM = Core::Instance ()->GetProxy ()->GetRootWindowsManager ();
				if (QMessageBox::question (rootWM->GetPreferredWindow (),
							"LeechCraft",
							tr ("Torrent file generated: %1.<br />Do you want to start seeding now?")
								.arg (QDir::toNativeSeparators (filename)),
							QMessageBox::Yes | QMessageBox::No) ==
						QMessageBox::Yes)
					Core::Instance ()->AddFile (filename,
#if LIBTORRENT_VERSION_NUM >= 1600
							QString::fromUtf8 (fullPath.c_str ()),
#else
							QString::fromUtf8 (fullPath.branch_path ().string ().c_str ()),
#endif
							QStringList (),
							false);
			}
Exemplo n.º 5
0
	void Plugin::handleShowList ()
	{
		auto rootWM = Proxy_->GetRootWindowsManager ();

		ICoreTabWidget *tw = rootWM->GetTabWidget (rootWM->GetPreferredWindowIndex ());

		if (tw->WidgetCount () < 2)
			return;

		QWidget *widget = new QWidget (nullptr,
				Qt::Popup | Qt::FramelessWindowHint);
		widget->setAttribute (Qt::WA_TranslucentBackground);
		widget->setWindowModality (Qt::ApplicationModal);

		QVBoxLayout *layout = new QVBoxLayout ();
		layout->setSpacing (1);
		layout->setContentsMargins (1, 1, 1, 1);

		const int currentIdx = tw->CurrentIndex ();
		QToolButton *toFocus = 0;
		QList<QToolButton*> allButtons;
		for (int i = 0, count = tw->WidgetCount (); i < count; ++i)
		{
			const QString& origText = tw->TabText (i);
			QString title = QString ("[%1] ").arg (i + 1) + origText;
			if (title.size () > 100)
				title = title.left (100) + "...";
			QAction *action = new QAction (tw->TabIcon (i), title, this);
			action->setToolTip (origText);
			action->setProperty ("TabIndex", i);
			action->setProperty ("ICTW", QVariant::fromValue<ICoreTabWidget*> (tw));
			connect (action,
					SIGNAL (triggered ()),
					this,
					SLOT (navigateToTab ()));
			connect (action,
					SIGNAL (triggered ()),
					widget,
					SLOT (deleteLater ()));

			auto button = new QToolButton ();
			button->setDefaultAction (action);
			button->setToolButtonStyle (Qt::ToolButtonTextBesideIcon);
			button->setSizePolicy (QSizePolicy::Expanding,
					button->sizePolicy ().verticalPolicy ());
			button->setProperty ("OrigText", origText);

			layout->addWidget (button);

			if (currentIdx == i)
				toFocus = button;

			allButtons << button;
		}

		widget->installEventFilter (new ListEventFilter (allButtons, this, widget));
		widget->setLayout (layout);
		layout->update ();
		layout->activate ();

		const QRect& rect = QApplication::desktop ()->
				screenGeometry (rootWM->GetPreferredWindow ());
		QPoint pos = rect.center ();

		const QSize& size = widget->sizeHint () / 2;
		pos -= QPoint (size.width (), size.height ());

		widget->move (pos);
		widget->show ();

		if (toFocus)
			toFocus->setFocus ();
	}