2008-02-13 03:00:21 +00:00
|
|
|
/*
|
2021-10-18 20:22:31 +00:00
|
|
|
* This file Copyright (C) 2010-2021 Mnemosyne LLC
|
2008-02-13 03:00:21 +00:00
|
|
|
*
|
2014-01-21 03:10:30 +00:00
|
|
|
* It may be used under the GNU GPL versions 2 or 3
|
2014-01-19 01:09:44 +00:00
|
|
|
* or any future license endorsed by Mnemosyne LLC.
|
2008-09-23 19:11:04 +00:00
|
|
|
*
|
2008-02-13 03:00:21 +00:00
|
|
|
*/
|
|
|
|
|
2021-10-18 20:22:31 +00:00
|
|
|
#include <cctype>
|
2010-02-05 12:35:29 +00:00
|
|
|
#include <string.h>
|
|
|
|
|
2021-10-18 20:22:31 +00:00
|
|
|
#include <glibmm.h>
|
|
|
|
#include <glibmm/i18n.h>
|
|
|
|
|
2010-12-22 07:04:11 +00:00
|
|
|
#include <libtransmission/transmission.h>
|
2017-04-21 07:40:57 +00:00
|
|
|
#include <libtransmission/file.h> /* tr_sys_path_is_same() */
|
2010-12-22 07:04:11 +00:00
|
|
|
|
2021-11-01 00:11:23 +00:00
|
|
|
#include "FileList.h"
|
|
|
|
#include "FreeSpaceLabel.h"
|
|
|
|
#include "HigWorkarea.h"
|
|
|
|
#include "OptionsDialog.h"
|
|
|
|
#include "Prefs.h"
|
|
|
|
#include "PrefsDialog.h"
|
|
|
|
#include "Session.h"
|
|
|
|
#include "Utils.h" /* gtr_priority_combo_get_value() */
|
2008-02-13 03:00:21 +00:00
|
|
|
|
2008-07-02 00:17:27 +00:00
|
|
|
/****
|
|
|
|
*****
|
|
|
|
****/
|
|
|
|
|
2021-10-18 20:22:31 +00:00
|
|
|
namespace
|
|
|
|
{
|
|
|
|
|
2021-12-14 08:43:27 +00:00
|
|
|
auto const MaxRecentDestinations = size_t{ 4 };
|
2008-07-02 00:17:27 +00:00
|
|
|
|
2021-10-18 20:22:31 +00:00
|
|
|
std::list<std::string> get_recent_destinations()
|
2008-07-02 00:17:27 +00:00
|
|
|
{
|
2021-10-18 20:22:31 +00:00
|
|
|
std::list<std::string> list;
|
2008-09-23 19:11:04 +00:00
|
|
|
|
2021-12-14 08:43:27 +00:00
|
|
|
for (size_t i = 0; i < MaxRecentDestinations; ++i)
|
2008-07-02 00:17:27 +00:00
|
|
|
{
|
2021-10-18 20:22:31 +00:00
|
|
|
auto const key = gtr_sprintf("recent-download-dir-%d", i + 1);
|
2017-04-19 12:04:45 +00:00
|
|
|
|
2021-10-18 20:22:31 +00:00
|
|
|
if (auto const val = gtr_pref_string_get(tr_quark_new({ key.c_str(), key.size() })); !val.empty())
|
2017-04-19 12:04:45 +00:00
|
|
|
{
|
2021-10-18 20:22:31 +00:00
|
|
|
list.push_back(val);
|
2017-04-19 12:04:45 +00:00
|
|
|
}
|
2008-07-02 00:17:27 +00:00
|
|
|
}
|
2013-07-20 16:19:15 +00:00
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
return list;
|
2008-07-02 00:17:27 +00:00
|
|
|
}
|
|
|
|
|
2021-11-01 00:11:23 +00:00
|
|
|
void save_recent_destination(Glib::RefPtr<Session> const& core, std::string const& dir)
|
2008-07-02 00:17:27 +00:00
|
|
|
{
|
2021-10-18 20:22:31 +00:00
|
|
|
if (dir.empty())
|
2017-04-19 12:04:45 +00:00
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
2013-07-20 16:19:15 +00:00
|
|
|
|
2021-10-18 20:22:31 +00:00
|
|
|
auto list = get_recent_destinations();
|
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
/* if it was already in the list, remove it */
|
2021-10-18 20:22:31 +00:00
|
|
|
list.remove(dir);
|
2013-07-20 16:19:15 +00:00
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
/* add it to the front of the list */
|
2021-10-18 20:22:31 +00:00
|
|
|
list.push_front(dir);
|
2013-07-20 16:19:15 +00:00
|
|
|
|
2021-12-14 08:43:27 +00:00
|
|
|
/* save the first MaxRecentDestinations directories */
|
|
|
|
list.resize(MaxRecentDestinations);
|
2021-10-18 20:22:31 +00:00
|
|
|
int i = 0;
|
|
|
|
for (auto const& d : list)
|
2013-07-20 16:19:15 +00:00
|
|
|
{
|
2021-10-18 20:22:31 +00:00
|
|
|
auto const key = gtr_sprintf("recent-download-dir-%d", ++i);
|
|
|
|
gtr_pref_string_set(tr_quark_new({ key.c_str(), key.size() }), d);
|
2008-07-02 00:17:27 +00:00
|
|
|
}
|
|
|
|
|
2021-10-18 20:22:31 +00:00
|
|
|
gtr_pref_save(core->get_session());
|
2008-07-02 00:17:27 +00:00
|
|
|
}
|
|
|
|
|
2021-10-18 20:22:31 +00:00
|
|
|
} // namespace
|
|
|
|
|
2008-07-02 00:17:27 +00:00
|
|
|
/****
|
|
|
|
*****
|
|
|
|
****/
|
|
|
|
|
2021-10-18 20:22:31 +00:00
|
|
|
class OptionsDialog::Impl
|
2008-02-13 03:00:21 +00:00
|
|
|
{
|
2021-10-18 20:22:31 +00:00
|
|
|
public:
|
2021-11-01 00:11:23 +00:00
|
|
|
Impl(OptionsDialog& dialog, Glib::RefPtr<Session> const& core, std::unique_ptr<tr_ctor, void (*)(tr_ctor*)> ctor);
|
2021-10-18 20:22:31 +00:00
|
|
|
|
2021-12-14 08:43:27 +00:00
|
|
|
TR_DISABLE_COPY_MOVE(Impl)
|
|
|
|
|
2021-10-18 20:22:31 +00:00
|
|
|
private:
|
|
|
|
void sourceChanged(Gtk::FileChooserButton* b);
|
|
|
|
void downloadDirChanged(Gtk::FileChooserButton* b);
|
|
|
|
|
|
|
|
void removeOldTorrent();
|
|
|
|
void updateTorrent();
|
|
|
|
|
|
|
|
void addResponseCB(int response);
|
|
|
|
|
|
|
|
private:
|
|
|
|
OptionsDialog& dialog_;
|
|
|
|
|
2021-11-01 00:11:23 +00:00
|
|
|
Glib::RefPtr<Session> const core_;
|
2021-10-18 20:22:31 +00:00
|
|
|
FileList* file_list_ = nullptr;
|
|
|
|
Gtk::CheckButton* run_check_ = nullptr;
|
|
|
|
Gtk::CheckButton* trash_check_ = nullptr;
|
|
|
|
Gtk::ComboBox* priority_combo_ = nullptr;
|
|
|
|
FreeSpaceLabel* freespace_label_ = nullptr;
|
|
|
|
std::string filename_;
|
|
|
|
std::string downloadDir_;
|
|
|
|
tr_torrent* tor_ = nullptr;
|
|
|
|
std::unique_ptr<tr_ctor, void (*)(tr_ctor*)> ctor_;
|
2008-02-13 03:00:21 +00:00
|
|
|
};
|
|
|
|
|
2021-10-18 20:22:31 +00:00
|
|
|
void OptionsDialog::Impl::removeOldTorrent()
|
2008-02-13 03:00:21 +00:00
|
|
|
{
|
2021-10-18 20:22:31 +00:00
|
|
|
if (tor_ != nullptr)
|
2008-02-13 03:00:21 +00:00
|
|
|
{
|
2021-10-18 20:22:31 +00:00
|
|
|
file_list_->clear();
|
|
|
|
tr_torrentRemove(tor_, false, nullptr);
|
|
|
|
tor_ = nullptr;
|
2008-02-13 03:00:21 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-10-18 20:22:31 +00:00
|
|
|
void OptionsDialog::Impl::addResponseCB(int response)
|
2008-02-13 03:00:21 +00:00
|
|
|
{
|
2021-10-18 20:22:31 +00:00
|
|
|
if (tor_ != nullptr)
|
2008-02-13 03:00:21 +00:00
|
|
|
{
|
2021-10-18 20:22:31 +00:00
|
|
|
if (response != Gtk::RESPONSE_ACCEPT)
|
2008-12-13 23:17:36 +00:00
|
|
|
{
|
2021-10-18 20:22:31 +00:00
|
|
|
removeOldTorrent();
|
2008-12-13 23:17:36 +00:00
|
|
|
}
|
2017-04-19 12:04:45 +00:00
|
|
|
else
|
2008-09-23 19:11:04 +00:00
|
|
|
{
|
2021-10-18 20:22:31 +00:00
|
|
|
tr_torrentSetPriority(tor_, gtr_priority_combo_get_value(*priority_combo_));
|
2010-02-02 07:51:45 +00:00
|
|
|
|
2021-10-18 20:22:31 +00:00
|
|
|
if (run_check_->get_active())
|
2017-04-19 12:04:45 +00:00
|
|
|
{
|
2021-10-18 20:22:31 +00:00
|
|
|
tr_torrentStart(tor_);
|
2017-04-19 12:04:45 +00:00
|
|
|
}
|
2008-12-13 23:17:36 +00:00
|
|
|
|
2021-10-18 20:22:31 +00:00
|
|
|
core_->add_torrent(tor_, false);
|
2008-12-13 23:17:36 +00:00
|
|
|
|
2021-10-18 20:22:31 +00:00
|
|
|
if (trash_check_->get_active())
|
2017-04-19 12:04:45 +00:00
|
|
|
{
|
2021-10-18 20:22:31 +00:00
|
|
|
gtr_file_trash_or_remove(filename_, nullptr);
|
2017-04-19 12:04:45 +00:00
|
|
|
}
|
2008-12-13 23:17:36 +00:00
|
|
|
|
2021-10-18 20:22:31 +00:00
|
|
|
save_recent_destination(core_, downloadDir_);
|
2008-02-13 03:00:21 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-10-18 20:22:31 +00:00
|
|
|
dialog_.hide();
|
2008-02-13 03:00:21 +00:00
|
|
|
}
|
|
|
|
|
2021-10-18 20:22:31 +00:00
|
|
|
void OptionsDialog::Impl::updateTorrent()
|
2008-02-13 03:00:21 +00:00
|
|
|
{
|
2021-10-18 20:22:31 +00:00
|
|
|
bool const isLocalFile = tr_ctorGetSourceFile(ctor_.get()) != nullptr;
|
|
|
|
trash_check_->set_sensitive(isLocalFile);
|
2010-05-13 13:12:27 +00:00
|
|
|
|
2021-10-18 20:22:31 +00:00
|
|
|
if (tor_ == nullptr)
|
2010-05-13 13:12:27 +00:00
|
|
|
{
|
2021-10-18 20:22:31 +00:00
|
|
|
file_list_->clear();
|
|
|
|
file_list_->set_sensitive(false);
|
2010-05-13 13:12:27 +00:00
|
|
|
}
|
2017-04-19 12:04:45 +00:00
|
|
|
else
|
2010-05-13 13:12:27 +00:00
|
|
|
{
|
2021-10-18 20:22:31 +00:00
|
|
|
tr_torrentSetDownloadDir(tor_, downloadDir_.c_str());
|
|
|
|
file_list_->set_sensitive(tr_torrentHasMetadata(tor_));
|
|
|
|
file_list_->set_torrent(tr_torrentId(tor_));
|
|
|
|
tr_torrentVerify(tor_, nullptr, nullptr);
|
2009-04-24 01:37:04 +00:00
|
|
|
}
|
2008-02-13 03:00:21 +00:00
|
|
|
}
|
|
|
|
|
2008-08-14 03:37:02 +00:00
|
|
|
/**
|
|
|
|
* When the source .torrent file is deleted
|
|
|
|
* (such as, if it was a temp file that a web browser passed to us),
|
2021-10-06 16:32:17 +00:00
|
|
|
* gtk invokes this callback and `filename' will be nullptr.
|
2008-08-14 03:37:02 +00:00
|
|
|
* The `filename' tests here are to prevent us from losing the current
|
|
|
|
* metadata when that happens.
|
|
|
|
*/
|
2021-10-18 20:22:31 +00:00
|
|
|
void OptionsDialog::Impl::sourceChanged(Gtk::FileChooserButton* b)
|
2008-02-13 03:00:21 +00:00
|
|
|
{
|
2021-10-18 20:22:31 +00:00
|
|
|
auto const filename = b->get_filename();
|
2008-02-13 03:00:21 +00:00
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
/* maybe instantiate a torrent */
|
2021-10-18 20:22:31 +00:00
|
|
|
if (!filename.empty() || tor_ == nullptr)
|
2008-08-14 03:37:02 +00:00
|
|
|
{
|
2017-04-30 16:25:26 +00:00
|
|
|
bool new_file = false;
|
2008-08-14 03:37:02 +00:00
|
|
|
|
2021-10-18 20:22:31 +00:00
|
|
|
if (!filename.empty() && (filename_.empty() || !tr_sys_path_is_same(filename.c_str(), filename_.c_str(), nullptr)))
|
2008-08-14 03:37:02 +00:00
|
|
|
{
|
2021-10-18 20:22:31 +00:00
|
|
|
filename_ = filename;
|
2021-12-26 16:25:07 +00:00
|
|
|
tr_ctorSetMetainfoFromFile(ctor_.get(), filename_.c_str(), nullptr);
|
2017-04-30 16:25:26 +00:00
|
|
|
new_file = true;
|
2008-08-14 03:37:02 +00:00
|
|
|
}
|
|
|
|
|
2021-10-18 20:22:31 +00:00
|
|
|
tr_ctorSetDownloadDir(ctor_.get(), TR_FORCE, downloadDir_.c_str());
|
|
|
|
tr_ctorSetPaused(ctor_.get(), TR_FORCE, true);
|
|
|
|
tr_ctorSetDeleteSource(ctor_.get(), false);
|
2008-08-14 03:37:02 +00:00
|
|
|
|
2021-12-24 22:05:17 +00:00
|
|
|
tr_torrent* duplicate_of = nullptr;
|
|
|
|
if (tr_torrent* const torrent = tr_torrentNew(ctor_.get(), &duplicate_of); torrent != nullptr)
|
2008-09-23 19:11:04 +00:00
|
|
|
{
|
2021-10-18 20:22:31 +00:00
|
|
|
removeOldTorrent();
|
|
|
|
tor_ = torrent;
|
2008-09-23 19:11:04 +00:00
|
|
|
}
|
2017-04-19 12:04:45 +00:00
|
|
|
else if (new_file)
|
2008-09-23 19:11:04 +00:00
|
|
|
{
|
2021-12-24 22:05:17 +00:00
|
|
|
gtr_add_torrent_error_dialog(*b, duplicate_of, filename_);
|
2008-08-14 03:37:02 +00:00
|
|
|
}
|
|
|
|
|
2021-10-18 20:22:31 +00:00
|
|
|
updateTorrent();
|
2008-02-13 03:00:21 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-10-18 20:22:31 +00:00
|
|
|
void OptionsDialog::Impl::downloadDirChanged(Gtk::FileChooserButton* b)
|
2008-02-13 03:00:21 +00:00
|
|
|
{
|
2021-10-18 20:22:31 +00:00
|
|
|
auto const fname = b->get_filename();
|
2008-08-14 03:37:02 +00:00
|
|
|
|
2021-10-18 20:22:31 +00:00
|
|
|
if (!fname.empty() && (downloadDir_.empty() || !tr_sys_path_is_same(fname.c_str(), downloadDir_.c_str(), nullptr)))
|
2008-04-13 01:36:53 +00:00
|
|
|
{
|
2021-10-18 20:22:31 +00:00
|
|
|
downloadDir_ = fname;
|
|
|
|
updateTorrent();
|
2013-02-09 04:05:03 +00:00
|
|
|
|
2021-10-18 20:22:31 +00:00
|
|
|
freespace_label_->set_dir(downloadDir_);
|
2008-04-13 01:36:53 +00:00
|
|
|
}
|
2008-02-13 03:00:21 +00:00
|
|
|
}
|
|
|
|
|
2021-10-18 20:22:31 +00:00
|
|
|
namespace
|
2008-03-19 20:34:35 +00:00
|
|
|
{
|
|
|
|
|
2021-10-18 20:22:31 +00:00
|
|
|
void addTorrentFilters(Gtk::FileChooser* chooser)
|
|
|
|
{
|
|
|
|
auto filter = Gtk::FileFilter::create();
|
|
|
|
filter->set_name(_("Torrent files"));
|
|
|
|
filter->add_pattern("*.torrent");
|
|
|
|
chooser->add_filter(filter);
|
|
|
|
|
|
|
|
filter = Gtk::FileFilter::create();
|
|
|
|
filter->set_name(_("All files"));
|
|
|
|
filter->add_pattern("*");
|
|
|
|
chooser->add_filter(filter);
|
2008-03-19 20:34:35 +00:00
|
|
|
}
|
|
|
|
|
2021-10-18 20:22:31 +00:00
|
|
|
} // namespace
|
|
|
|
|
2008-02-13 03:00:21 +00:00
|
|
|
/****
|
|
|
|
*****
|
|
|
|
****/
|
|
|
|
|
2021-10-18 20:22:31 +00:00
|
|
|
std::unique_ptr<OptionsDialog> OptionsDialog::create(
|
|
|
|
Gtk::Window& parent,
|
2021-11-01 00:11:23 +00:00
|
|
|
Glib::RefPtr<Session> const& core,
|
2021-10-18 20:22:31 +00:00
|
|
|
std::unique_ptr<tr_ctor, void (*)(tr_ctor*)> ctor)
|
2008-02-13 03:00:21 +00:00
|
|
|
{
|
2021-10-18 20:22:31 +00:00
|
|
|
return std::unique_ptr<OptionsDialog>(new OptionsDialog(parent, core, std::move(ctor)));
|
|
|
|
}
|
|
|
|
|
|
|
|
OptionsDialog::OptionsDialog(
|
|
|
|
Gtk::Window& parent,
|
2021-11-01 00:11:23 +00:00
|
|
|
Glib::RefPtr<Session> const& core,
|
2021-10-18 20:22:31 +00:00
|
|
|
std::unique_ptr<tr_ctor, void (*)(tr_ctor*)> ctor)
|
|
|
|
: Gtk::Dialog(_("Torrent Options"), parent)
|
|
|
|
, impl_(std::make_unique<Impl>(*this, core, std::move(ctor)))
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
OptionsDialog::~OptionsDialog() = default;
|
|
|
|
|
|
|
|
OptionsDialog::Impl::Impl(
|
|
|
|
OptionsDialog& dialog,
|
2021-11-01 00:11:23 +00:00
|
|
|
Glib::RefPtr<Session> const& core,
|
2021-10-18 20:22:31 +00:00
|
|
|
std::unique_ptr<tr_ctor, void (*)(tr_ctor*)> ctor)
|
|
|
|
: dialog_(dialog)
|
|
|
|
, core_(core)
|
|
|
|
, ctor_(std::move(ctor))
|
|
|
|
{
|
|
|
|
int row = 0;
|
2017-04-19 12:04:45 +00:00
|
|
|
|
|
|
|
/* make the dialog */
|
2021-10-18 20:22:31 +00:00
|
|
|
dialog_.add_button(_("_Cancel"), Gtk::RESPONSE_CANCEL);
|
|
|
|
dialog_.add_button(_("_Open"), Gtk::RESPONSE_ACCEPT);
|
|
|
|
dialog_.set_default_response(Gtk::RESPONSE_ACCEPT);
|
|
|
|
|
|
|
|
char const* str = nullptr;
|
|
|
|
if (!tr_ctorGetDownloadDir(ctor_.get(), TR_FORCE, &str))
|
2017-04-19 12:04:45 +00:00
|
|
|
{
|
|
|
|
g_assert_not_reached();
|
|
|
|
}
|
|
|
|
|
2021-10-18 20:22:31 +00:00
|
|
|
g_assert(str != nullptr);
|
2017-04-19 12:04:45 +00:00
|
|
|
|
2021-10-18 20:22:31 +00:00
|
|
|
filename_ = tr_ctorGetSourceFile(ctor_.get()) != nullptr ? tr_ctorGetSourceFile(ctor_.get()) : "";
|
|
|
|
downloadDir_ = str;
|
|
|
|
file_list_ = Gtk::make_managed<FileList>(core_, 0);
|
|
|
|
trash_check_ = Gtk::make_managed<Gtk::CheckButton>(_("Mo_ve .torrent file to the trash"), true);
|
|
|
|
run_check_ = Gtk::make_managed<Gtk::CheckButton>(_("_Start when added"), true);
|
2017-04-19 12:04:45 +00:00
|
|
|
|
2021-10-18 20:22:31 +00:00
|
|
|
priority_combo_ = gtr_priority_combo_new();
|
|
|
|
gtr_priority_combo_set_value(*priority_combo_, TR_PRI_NORMAL);
|
2017-04-19 12:04:45 +00:00
|
|
|
|
2021-11-12 09:12:50 +00:00
|
|
|
dialog.signal_response().connect(sigc::mem_fun(*this, &Impl::addResponseCB));
|
2017-04-19 12:04:45 +00:00
|
|
|
|
2021-10-18 20:22:31 +00:00
|
|
|
auto* grid = Gtk::make_managed<Gtk::Grid>();
|
|
|
|
grid->set_border_width(GUI_PAD_BIG);
|
|
|
|
grid->set_row_spacing(GUI_PAD);
|
|
|
|
grid->set_column_spacing(GUI_PAD_BIG);
|
2017-04-19 12:04:45 +00:00
|
|
|
|
|
|
|
/* "torrent file" row */
|
2021-10-18 20:22:31 +00:00
|
|
|
auto* source_label = Gtk::make_managed<Gtk::Label>(_("_Torrent file:"), true);
|
|
|
|
source_label->set_halign(Gtk::ALIGN_START);
|
|
|
|
source_label->set_halign(Gtk::ALIGN_CENTER);
|
|
|
|
grid->attach(*source_label, 0, row, 1, 1);
|
|
|
|
auto* source_chooser = Gtk::make_managed<Gtk::FileChooserButton>(_("Select Source File"), Gtk::FILE_CHOOSER_ACTION_OPEN);
|
|
|
|
source_chooser->set_hexpand(true);
|
|
|
|
grid->attach_next_to(*source_chooser, *source_label, Gtk::POS_RIGHT);
|
|
|
|
source_label->set_mnemonic_widget(*source_chooser);
|
|
|
|
addTorrentFilters(source_chooser);
|
|
|
|
source_chooser->signal_selection_changed().connect([this, source_chooser]() { sourceChanged(source_chooser); });
|
2017-04-19 12:04:45 +00:00
|
|
|
|
|
|
|
/* "destination folder" row */
|
|
|
|
row++;
|
2021-10-18 20:22:31 +00:00
|
|
|
auto* destination_label = Gtk::make_managed<Gtk::Label>(_("_Destination folder:"), true);
|
|
|
|
destination_label->set_halign(Gtk::ALIGN_START);
|
|
|
|
destination_label->set_valign(Gtk::ALIGN_CENTER);
|
|
|
|
grid->attach(*destination_label, 0, row, 1, 1);
|
|
|
|
auto* destination_chooser = Gtk::make_managed<Gtk::FileChooserButton>(
|
|
|
|
_("Select Destination Folder"),
|
|
|
|
Gtk::FILE_CHOOSER_ACTION_SELECT_FOLDER);
|
|
|
|
|
|
|
|
if (!destination_chooser->set_current_folder(downloadDir_))
|
2017-04-19 12:04:45 +00:00
|
|
|
{
|
2021-10-18 20:22:31 +00:00
|
|
|
g_warning("couldn't select '%s'", downloadDir_.c_str());
|
2017-04-19 12:04:45 +00:00
|
|
|
}
|
|
|
|
|
2021-10-18 20:22:31 +00:00
|
|
|
for (auto const& folder : get_recent_destinations())
|
2017-04-19 12:04:45 +00:00
|
|
|
{
|
2021-10-18 20:22:31 +00:00
|
|
|
destination_chooser->add_shortcut_folder(folder);
|
2017-04-19 12:04:45 +00:00
|
|
|
}
|
|
|
|
|
2021-10-18 20:22:31 +00:00
|
|
|
grid->attach_next_to(*destination_chooser, *destination_label, Gtk::POS_RIGHT);
|
|
|
|
destination_label->set_mnemonic_widget(*destination_chooser);
|
|
|
|
destination_chooser->signal_selection_changed().connect([this, destination_chooser]()
|
|
|
|
{ downloadDirChanged(destination_chooser); });
|
2017-04-19 12:04:45 +00:00
|
|
|
|
|
|
|
row++;
|
2021-10-18 20:22:31 +00:00
|
|
|
freespace_label_ = Gtk::make_managed<FreeSpaceLabel>(core_, downloadDir_);
|
|
|
|
freespace_label_->set_margin_bottom(GUI_PAD_BIG);
|
|
|
|
freespace_label_->set_halign(Gtk::ALIGN_END);
|
|
|
|
freespace_label_->set_valign(Gtk::ALIGN_CENTER);
|
|
|
|
grid->attach(*freespace_label_, 0, row, 2, 1);
|
2017-04-19 12:04:45 +00:00
|
|
|
|
|
|
|
/* file list row */
|
|
|
|
row++;
|
2021-10-18 20:22:31 +00:00
|
|
|
file_list_->set_vexpand(true);
|
|
|
|
file_list_->set_size_request(466U, 300U);
|
|
|
|
grid->attach(*file_list_, 0, row, 2, 1);
|
2017-04-19 12:04:45 +00:00
|
|
|
|
|
|
|
/* torrent priority row */
|
|
|
|
row++;
|
2021-10-18 20:22:31 +00:00
|
|
|
auto* priority_label = Gtk::make_managed<Gtk::Label>(_("Torrent _priority:"), true);
|
|
|
|
priority_label->set_halign(Gtk::ALIGN_START);
|
|
|
|
priority_label->set_valign(Gtk::ALIGN_CENTER);
|
|
|
|
grid->attach(*priority_label, 0, row, 1, 1);
|
|
|
|
priority_label->set_mnemonic_widget(*priority_combo_);
|
|
|
|
grid->attach_next_to(*priority_combo_, *priority_label, Gtk::POS_RIGHT);
|
2017-04-19 12:04:45 +00:00
|
|
|
|
|
|
|
/* torrent priority row */
|
|
|
|
row++;
|
|
|
|
|
2021-10-18 20:22:31 +00:00
|
|
|
bool flag;
|
|
|
|
if (!tr_ctorGetPaused(ctor_.get(), TR_FORCE, &flag))
|
2017-04-19 12:04:45 +00:00
|
|
|
{
|
|
|
|
g_assert_not_reached();
|
|
|
|
}
|
|
|
|
|
2021-10-18 20:22:31 +00:00
|
|
|
run_check_->set_active(!flag);
|
|
|
|
grid->attach(*run_check_, 0, row, 2, 1);
|
2017-04-19 12:04:45 +00:00
|
|
|
|
|
|
|
/* "trash .torrent file" row */
|
|
|
|
row++;
|
|
|
|
|
2021-10-18 20:22:31 +00:00
|
|
|
if (!tr_ctorGetDeleteSource(ctor_.get(), &flag))
|
2017-04-19 12:04:45 +00:00
|
|
|
{
|
|
|
|
g_assert_not_reached();
|
|
|
|
}
|
|
|
|
|
2021-10-18 20:22:31 +00:00
|
|
|
trash_check_->set_active(flag);
|
|
|
|
grid->attach(*trash_check_, 0, row, 2, 1);
|
2017-04-19 12:04:45 +00:00
|
|
|
|
|
|
|
/* trigger sourceChanged, either directly or indirectly,
|
|
|
|
* so that it creates the tor/gtor objects */
|
2021-10-18 20:22:31 +00:00
|
|
|
if (!filename_.empty())
|
2017-04-19 12:04:45 +00:00
|
|
|
{
|
2021-10-18 20:22:31 +00:00
|
|
|
source_chooser->set_filename(filename_);
|
2017-04-19 12:04:45 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2021-10-18 20:22:31 +00:00
|
|
|
sourceChanged(source_chooser);
|
2017-04-19 12:04:45 +00:00
|
|
|
}
|
|
|
|
|
2021-10-18 20:22:31 +00:00
|
|
|
gtr_dialog_set_content(dialog_, *grid);
|
|
|
|
dialog_.get_widget_for_response(Gtk::RESPONSE_ACCEPT)->grab_focus();
|
2008-02-13 03:00:21 +00:00
|
|
|
}
|
2008-03-18 01:22:11 +00:00
|
|
|
|
|
|
|
/****
|
|
|
|
*****
|
|
|
|
****/
|
|
|
|
|
2021-11-01 00:11:23 +00:00
|
|
|
void TorrentFileChooserDialog::onOpenDialogResponse(int response, Glib::RefPtr<Session> const& core)
|
2008-03-18 01:22:11 +00:00
|
|
|
{
|
2017-04-19 12:04:45 +00:00
|
|
|
/* remember this folder the next time we use this dialog */
|
2021-10-18 20:22:31 +00:00
|
|
|
gtr_pref_string_set(TR_KEY_open_dialog_dir, get_current_folder());
|
2008-03-18 20:41:27 +00:00
|
|
|
|
2021-10-18 20:22:31 +00:00
|
|
|
if (response == Gtk::RESPONSE_ACCEPT)
|
2008-03-19 14:54:32 +00:00
|
|
|
{
|
2021-10-18 20:22:31 +00:00
|
|
|
auto* tb = static_cast<Gtk::CheckButton*>(get_extra_widget());
|
|
|
|
bool const do_start = gtr_pref_flag_get(TR_KEY_start_added_torrents);
|
|
|
|
bool const do_prompt = tb->get_active();
|
|
|
|
bool const do_notify = false;
|
|
|
|
auto const files = get_files();
|
|
|
|
|
|
|
|
core->add_files(files, do_start, do_prompt, do_notify);
|
2008-03-18 01:22:11 +00:00
|
|
|
}
|
|
|
|
|
2021-10-18 20:22:31 +00:00
|
|
|
hide();
|
|
|
|
}
|
|
|
|
|
|
|
|
std::unique_ptr<TorrentFileChooserDialog> TorrentFileChooserDialog::create(
|
|
|
|
Gtk::Window& parent,
|
2021-11-01 00:11:23 +00:00
|
|
|
Glib::RefPtr<Session> const& core)
|
2021-10-18 20:22:31 +00:00
|
|
|
{
|
|
|
|
return std::unique_ptr<TorrentFileChooserDialog>(new TorrentFileChooserDialog(parent, core));
|
2008-03-18 01:22:11 +00:00
|
|
|
}
|
|
|
|
|
2021-11-01 00:11:23 +00:00
|
|
|
TorrentFileChooserDialog::TorrentFileChooserDialog(Gtk::Window& parent, Glib::RefPtr<Session> const& core)
|
2021-10-18 20:22:31 +00:00
|
|
|
: Gtk::FileChooserDialog(parent, _("Open a Torrent"), Gtk::FILE_CHOOSER_ACTION_OPEN)
|
2008-03-18 01:22:11 +00:00
|
|
|
{
|
2021-10-18 20:22:31 +00:00
|
|
|
add_button(_("_Cancel"), Gtk::RESPONSE_CANCEL);
|
|
|
|
add_button(_("_Open"), Gtk::RESPONSE_ACCEPT);
|
|
|
|
|
|
|
|
set_select_multiple(true);
|
|
|
|
addTorrentFilters(this);
|
|
|
|
signal_response().connect([this, core](int response) { onOpenDialogResponse(response, core); });
|
|
|
|
|
|
|
|
if (auto const folder = gtr_pref_string_get(TR_KEY_open_dialog_dir); !folder.empty())
|
2017-04-19 12:04:45 +00:00
|
|
|
{
|
2021-10-18 20:22:31 +00:00
|
|
|
set_current_folder(folder);
|
2017-04-19 12:04:45 +00:00
|
|
|
}
|
|
|
|
|
2021-10-18 20:22:31 +00:00
|
|
|
auto* c = Gtk::make_managed<Gtk::CheckButton>(_("Show _options dialog"), true);
|
|
|
|
c->set_active(gtr_pref_flag_get(TR_KEY_show_options_window));
|
|
|
|
set_extra_widget(*c);
|
|
|
|
c->show();
|
2008-03-18 01:22:11 +00:00
|
|
|
}
|
2008-09-23 19:11:04 +00:00
|
|
|
|
2009-11-22 16:20:22 +00:00
|
|
|
/***
|
|
|
|
****
|
|
|
|
***/
|
|
|
|
|
2021-11-01 00:11:23 +00:00
|
|
|
void TorrentUrlChooserDialog::onOpenURLResponse(int response, Glib::RefPtr<Session> const& core)
|
2009-11-22 16:20:22 +00:00
|
|
|
{
|
2017-04-19 12:04:45 +00:00
|
|
|
bool handled = false;
|
2009-11-22 16:20:22 +00:00
|
|
|
|
2021-10-18 20:22:31 +00:00
|
|
|
if (response == Gtk::RESPONSE_ACCEPT)
|
2009-11-22 16:20:22 +00:00
|
|
|
{
|
2021-10-18 20:22:31 +00:00
|
|
|
auto* e = static_cast<Gtk::Entry*>(get_data("url-entry"));
|
|
|
|
auto const url = gtr_str_strip(e->get_text());
|
2013-07-20 16:19:15 +00:00
|
|
|
|
2021-10-18 20:22:31 +00:00
|
|
|
if (!url.empty())
|
2013-07-20 16:19:15 +00:00
|
|
|
{
|
2021-10-18 20:22:31 +00:00
|
|
|
handled = core->add_from_url(url);
|
2017-04-19 12:04:45 +00:00
|
|
|
|
|
|
|
if (!handled)
|
|
|
|
{
|
2021-10-18 20:22:31 +00:00
|
|
|
gtr_unrecognized_url_dialog(*this, url);
|
2017-04-19 12:04:45 +00:00
|
|
|
}
|
2009-11-22 16:20:22 +00:00
|
|
|
}
|
|
|
|
}
|
2021-10-18 20:22:31 +00:00
|
|
|
else if (response == Gtk::RESPONSE_CANCEL)
|
2012-04-07 00:41:21 +00:00
|
|
|
{
|
2017-04-30 16:25:26 +00:00
|
|
|
handled = true;
|
2012-04-07 00:41:21 +00:00
|
|
|
}
|
2009-11-22 16:20:22 +00:00
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
if (handled)
|
|
|
|
{
|
2021-10-18 20:22:31 +00:00
|
|
|
hide();
|
2017-04-19 12:04:45 +00:00
|
|
|
}
|
2009-11-22 16:20:22 +00:00
|
|
|
}
|
|
|
|
|
2021-11-01 00:11:23 +00:00
|
|
|
std::unique_ptr<TorrentUrlChooserDialog> TorrentUrlChooserDialog::create(Gtk::Window& parent, Glib::RefPtr<Session> const& core)
|
2021-10-18 20:22:31 +00:00
|
|
|
{
|
|
|
|
return std::unique_ptr<TorrentUrlChooserDialog>(new TorrentUrlChooserDialog(parent, core));
|
|
|
|
}
|
|
|
|
|
2021-11-01 00:11:23 +00:00
|
|
|
TorrentUrlChooserDialog::TorrentUrlChooserDialog(Gtk::Window& parent, Glib::RefPtr<Session> const& core)
|
2021-10-18 20:22:31 +00:00
|
|
|
: Gtk::Dialog(_("Open URL"), parent)
|
2009-11-22 16:20:22 +00:00
|
|
|
{
|
2017-04-19 12:04:45 +00:00
|
|
|
guint row;
|
2021-10-18 20:22:31 +00:00
|
|
|
|
|
|
|
add_button(_("_Cancel"), Gtk::RESPONSE_CANCEL);
|
|
|
|
add_button(_("_Open"), Gtk::RESPONSE_ACCEPT);
|
|
|
|
signal_response().connect([this, core](int response) { onOpenURLResponse(response, core); });
|
2017-04-19 12:04:45 +00:00
|
|
|
|
|
|
|
row = 0;
|
2021-10-18 20:22:31 +00:00
|
|
|
auto* t = Gtk::make_managed<HigWorkarea>();
|
|
|
|
t->add_section_title(row, _("Open torrent from URL"));
|
|
|
|
auto* e = Gtk::make_managed<Gtk::Entry>();
|
|
|
|
e->set_size_request(400, -1);
|
|
|
|
gtr_paste_clipboard_url_into_entry(*e);
|
|
|
|
set_data("url-entry", e);
|
|
|
|
t->add_row(row, _("_URL"), *e);
|
2017-04-19 12:04:45 +00:00
|
|
|
|
2021-10-18 20:22:31 +00:00
|
|
|
gtr_dialog_set_content(*this, *t);
|
2017-04-19 12:04:45 +00:00
|
|
|
|
2021-10-18 20:22:31 +00:00
|
|
|
if (e->get_text_length() == 0)
|
2017-04-19 12:04:45 +00:00
|
|
|
{
|
2021-10-18 20:22:31 +00:00
|
|
|
e->grab_focus();
|
2017-04-19 12:04:45 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2021-10-18 20:22:31 +00:00
|
|
|
get_widget_for_response(Gtk::RESPONSE_ACCEPT)->grab_focus();
|
2017-04-19 12:04:45 +00:00
|
|
|
}
|
2009-11-22 16:20:22 +00:00
|
|
|
}
|