2023-11-01 21:11:11 +00:00
|
|
|
// This file Copyright © Mnemosyne LLC.
|
2022-02-07 16:25:02 +00:00
|
|
|
// It may be used under GPLv2 (SPDX: GPL-2.0-only), GPLv3 (SPDX: GPL-3.0-only),
|
2022-01-20 18:27:56 +00:00
|
|
|
// or any future license endorsed by Mnemosyne LLC.
|
|
|
|
// License text can be found in the licenses/ folder.
|
2008-02-13 03:00:21 +00:00
|
|
|
|
2022-12-26 21:13:21 +00:00
|
|
|
#include "OptionsDialog.h"
|
2010-12-22 07:04:11 +00:00
|
|
|
|
2021-11-01 00:11:23 +00:00
|
|
|
#include "FileList.h"
|
|
|
|
#include "FreeSpaceLabel.h"
|
2022-12-29 02:42:20 +00:00
|
|
|
#include "GtkCompat.h"
|
2022-10-08 22:50:03 +00:00
|
|
|
#include "PathButton.h"
|
2021-11-01 00:11:23 +00:00
|
|
|
#include "Prefs.h"
|
|
|
|
#include "PrefsDialog.h"
|
|
|
|
#include "Session.h"
|
2023-01-21 12:06:20 +00:00
|
|
|
#include "Utils.h"
|
2008-02-13 03:00:21 +00:00
|
|
|
|
2022-12-26 21:13:21 +00:00
|
|
|
#include <libtransmission/transmission.h>
|
|
|
|
#include <libtransmission/file.h> /* tr_sys_path_is_same() */
|
|
|
|
|
2022-12-27 01:43:20 +00:00
|
|
|
#include <giomm/file.h>
|
2022-12-26 21:13:21 +00:00
|
|
|
#include <glibmm/i18n.h>
|
2022-12-27 01:43:20 +00:00
|
|
|
#include <gtkmm/checkbutton.h>
|
|
|
|
#include <gtkmm/combobox.h>
|
|
|
|
#include <gtkmm/filefilter.h>
|
2022-12-26 21:13:21 +00:00
|
|
|
|
|
|
|
#include <memory>
|
|
|
|
#include <utility>
|
|
|
|
|
2022-11-15 00:53:12 +00:00
|
|
|
using namespace std::string_view_literals;
|
|
|
|
|
2008-07-02 00:17:27 +00:00
|
|
|
/****
|
|
|
|
*****
|
|
|
|
****/
|
|
|
|
|
2022-09-07 22:25:04 +00:00
|
|
|
namespace
|
|
|
|
{
|
|
|
|
|
2022-11-15 00:53:12 +00:00
|
|
|
auto const ShowOptionsDialogChoice = "show_options_dialog"sv; // TODO(C++20): Use ""s
|
2022-10-08 22:50:03 +00:00
|
|
|
|
2022-09-07 22:25:04 +00:00
|
|
|
std::string get_source_file(tr_ctor& ctor)
|
|
|
|
{
|
|
|
|
if (char const* source_file = tr_ctorGetSourceFile(&ctor); source_file != nullptr)
|
|
|
|
{
|
|
|
|
return source_file;
|
|
|
|
}
|
|
|
|
|
|
|
|
return "";
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string get_download_dir(tr_ctor& ctor)
|
|
|
|
{
|
|
|
|
char const* str = nullptr;
|
|
|
|
if (!tr_ctorGetDownloadDir(&ctor, TR_FORCE, &str))
|
|
|
|
{
|
|
|
|
g_assert_not_reached();
|
|
|
|
}
|
|
|
|
|
|
|
|
g_assert(str != nullptr);
|
|
|
|
return str;
|
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace
|
|
|
|
|
|
|
|
/****
|
|
|
|
*****
|
|
|
|
****/
|
|
|
|
|
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:
|
2022-09-07 22:25:04 +00:00
|
|
|
Impl(
|
|
|
|
OptionsDialog& dialog,
|
|
|
|
Glib::RefPtr<Gtk::Builder> const& builder,
|
|
|
|
Glib::RefPtr<Session> const& core,
|
|
|
|
std::unique_ptr<tr_ctor, void (*)(tr_ctor*)> ctor);
|
2022-11-13 17:36:16 +00:00
|
|
|
~Impl() = default;
|
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:
|
2022-10-08 22:50:03 +00:00
|
|
|
void sourceChanged(PathButton* b);
|
|
|
|
void downloadDirChanged(PathButton* b);
|
2021-10-18 20:22:31 +00:00
|
|
|
|
|
|
|
void removeOldTorrent();
|
|
|
|
void updateTorrent();
|
|
|
|
|
|
|
|
void addResponseCB(int response);
|
|
|
|
|
|
|
|
private:
|
|
|
|
OptionsDialog& dialog_;
|
2021-11-01 00:11:23 +00:00
|
|
|
Glib::RefPtr<Session> const core_;
|
2022-09-07 22:25:04 +00:00
|
|
|
std::unique_ptr<tr_ctor, void (*)(tr_ctor*)> ctor_;
|
|
|
|
|
|
|
|
std::string filename_;
|
|
|
|
std::string downloadDir_;
|
|
|
|
tr_torrent* tor_ = nullptr;
|
|
|
|
|
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;
|
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();
|
2022-10-23 16:51:35 +00:00
|
|
|
tr_torrentRemove(tor_, false, nullptr, nullptr);
|
2021-10-18 20:22:31 +00:00
|
|
|
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
|
|
|
{
|
2022-10-08 22:50:03 +00:00
|
|
|
if (response == TR_GTK_RESPONSE_TYPE(ACCEPT))
|
2008-09-23 19:11:04 +00:00
|
|
|
{
|
2023-12-23 16:32:04 +00:00
|
|
|
tr_torrentSetPriority(tor_, static_cast<tr_priority_t>(gtr_combo_box_get_active_enum(*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
|
|
|
|
2022-12-21 21:26:25 +00:00
|
|
|
core_->add_torrent(Torrent::create(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
|
|
|
|
2022-08-22 02:26:13 +00:00
|
|
|
gtr_save_recent_dir("download", core_, downloadDir_);
|
2008-02-13 03:00:21 +00:00
|
|
|
}
|
2022-10-08 22:50:03 +00:00
|
|
|
else if (response == TR_GTK_RESPONSE_TYPE(CANCEL))
|
|
|
|
{
|
|
|
|
removeOldTorrent();
|
|
|
|
}
|
2008-02-13 03:00:21 +00:00
|
|
|
}
|
|
|
|
|
2022-10-08 22:50:03 +00:00
|
|
|
dialog_.close();
|
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_));
|
2022-02-09 18:02:59 +00:00
|
|
|
tr_torrentVerify(tor_);
|
2009-04-24 01:37:04 +00:00
|
|
|
}
|
2008-02-13 03:00:21 +00:00
|
|
|
}
|
|
|
|
|
2008-08-14 03:37:02 +00:00
|
|
|
/**
|
2022-03-21 14:15:48 +00:00
|
|
|
* When the source torrent file is deleted
|
2008-08-14 03:37:02 +00:00
|
|
|
* (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.
|
|
|
|
*/
|
2022-10-08 22:50:03 +00:00
|
|
|
void OptionsDialog::Impl::sourceChanged(PathButton* 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
|
|
|
|
2022-05-22 01:17:00 +00:00
|
|
|
if (!filename.empty() && (filename_.empty() || !tr_sys_path_is_same(filename, filename_)))
|
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
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-10-08 22:50:03 +00:00
|
|
|
void OptionsDialog::Impl::downloadDirChanged(PathButton* 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
|
|
|
|
2022-05-22 01:17:00 +00:00
|
|
|
if (!fname.empty() && (downloadDir_.empty() || !tr_sys_path_is_same(fname, downloadDir_)))
|
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
|
|
|
{
|
|
|
|
|
2022-10-08 22:50:03 +00:00
|
|
|
template<typename FileChooserT>
|
|
|
|
void addTorrentFilters(FileChooserT* chooser)
|
2021-10-18 20:22:31 +00:00
|
|
|
{
|
|
|
|
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
|
|
|
/****
|
|
|
|
*****
|
|
|
|
****/
|
|
|
|
|
2022-09-07 22:25:04 +00:00
|
|
|
OptionsDialog::OptionsDialog(
|
|
|
|
BaseObjectType* cast_item,
|
|
|
|
Glib::RefPtr<Gtk::Builder> const& builder,
|
2021-10-18 20:22:31 +00:00
|
|
|
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)
|
2022-09-07 22:25:04 +00:00
|
|
|
: Gtk::Dialog(cast_item)
|
|
|
|
, impl_(std::make_unique<Impl>(*this, builder, core, std::move(ctor)))
|
2008-02-13 03:00:21 +00:00
|
|
|
{
|
2022-09-07 22:25:04 +00:00
|
|
|
set_transient_for(parent);
|
2021-10-18 20:22:31 +00:00
|
|
|
}
|
|
|
|
|
2022-09-07 22:25:04 +00:00
|
|
|
OptionsDialog::~OptionsDialog() = default;
|
|
|
|
|
|
|
|
std::unique_ptr<OptionsDialog> OptionsDialog::create(
|
2021-10-18 20:22:31 +00:00
|
|
|
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)
|
|
|
|
{
|
2022-09-07 22:25:04 +00:00
|
|
|
auto const builder = Gtk::Builder::create_from_resource(gtr_get_full_resource_path("OptionsDialog.ui"));
|
|
|
|
return std::unique_ptr<OptionsDialog>(
|
|
|
|
gtr_get_widget_derived<OptionsDialog>(builder, "OptionsDialog", parent, core, std::move(ctor)));
|
2021-10-18 20:22:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
OptionsDialog::Impl::Impl(
|
|
|
|
OptionsDialog& dialog,
|
2022-09-07 22:25:04 +00:00
|
|
|
Glib::RefPtr<Gtk::Builder> const& builder,
|
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))
|
2022-09-07 22:25:04 +00:00
|
|
|
, filename_(get_source_file(*ctor_))
|
|
|
|
, downloadDir_(get_download_dir(*ctor_))
|
|
|
|
, file_list_(gtr_get_widget_derived<FileList>(builder, "files_view_scroll", "files_view", core_, 0))
|
|
|
|
, run_check_(gtr_get_widget<Gtk::CheckButton>(builder, "start_check"))
|
|
|
|
, trash_check_(gtr_get_widget<Gtk::CheckButton>(builder, "trash_check"))
|
|
|
|
, priority_combo_(gtr_get_widget<Gtk::ComboBox>(builder, "priority_combo"))
|
|
|
|
, freespace_label_(gtr_get_widget_derived<FreeSpaceLabel>(builder, "free_space_label", core_, downloadDir_))
|
2021-10-18 20:22:31 +00:00
|
|
|
{
|
2022-09-10 13:19:54 +00:00
|
|
|
dialog_.set_default_response(TR_GTK_RESPONSE_TYPE(ACCEPT));
|
2022-09-07 22:25:04 +00:00
|
|
|
dialog.signal_response().connect(sigc::mem_fun(*this, &Impl::addResponseCB));
|
2021-10-18 20:22:31 +00:00
|
|
|
|
2022-09-07 22:25:04 +00:00
|
|
|
gtr_priority_combo_init(*priority_combo_);
|
2023-01-21 12:06:20 +00:00
|
|
|
gtr_combo_box_set_active_enum(*priority_combo_, TR_PRI_NORMAL);
|
2017-04-19 12:04:45 +00:00
|
|
|
|
2022-10-08 22:50:03 +00:00
|
|
|
auto* source_chooser = gtr_get_widget_derived<PathButton>(builder, "source_button");
|
2021-10-18 20:22:31 +00:00
|
|
|
addTorrentFilters(source_chooser);
|
|
|
|
source_chooser->signal_selection_changed().connect([this, source_chooser]() { sourceChanged(source_chooser); });
|
2017-04-19 12:04:45 +00:00
|
|
|
|
2022-10-08 22:50:03 +00:00
|
|
|
auto* destination_chooser = gtr_get_widget_derived<PathButton>(builder, "destination_button");
|
|
|
|
destination_chooser->set_filename(downloadDir_);
|
|
|
|
destination_chooser->set_shortcut_folders(gtr_get_recent_dirs("download"));
|
2017-04-19 12:04:45 +00:00
|
|
|
|
2021-10-18 20:22:31 +00:00
|
|
|
destination_chooser->signal_selection_changed().connect([this, destination_chooser]()
|
|
|
|
{ downloadDirChanged(destination_chooser); });
|
2017-04-19 12:04:45 +00:00
|
|
|
|
2022-11-13 17:36:16 +00:00
|
|
|
bool flag = false;
|
2021-10-18 20:22:31 +00:00
|
|
|
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);
|
2017-04-19 12:04:45 +00:00
|
|
|
|
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);
|
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
|
|
|
}
|
|
|
|
|
2022-09-10 13:19:54 +00:00
|
|
|
dialog_.get_widget_for_response(TR_GTK_RESPONSE_TYPE(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
|
|
|
{
|
2022-09-10 13:19:54 +00:00
|
|
|
if (response == TR_GTK_RESPONSE_TYPE(ACCEPT))
|
2008-03-19 14:54:32 +00:00
|
|
|
{
|
2021-10-18 20:22:31 +00:00
|
|
|
bool const do_start = gtr_pref_flag_get(TR_KEY_start_added_torrents);
|
2022-11-15 00:53:12 +00:00
|
|
|
bool const do_prompt = get_choice(std::string(ShowOptionsDialogChoice)) == "true";
|
2021-10-18 20:22:31 +00:00
|
|
|
bool const do_notify = false;
|
2022-10-08 22:50:03 +00:00
|
|
|
|
2023-10-20 22:13:18 +00:00
|
|
|
auto const files = IF_GTKMM4(get_files2, get_files)();
|
|
|
|
g_assert(!files.empty());
|
|
|
|
|
|
|
|
/* remember this folder the next time we use this dialog */
|
|
|
|
if (auto const folder = IF_GTKMM4(get_current_folder, get_current_folder_file)(); folder != nullptr)
|
|
|
|
{
|
|
|
|
gtr_pref_string_set(TR_KEY_open_dialog_dir, folder->get_path());
|
|
|
|
}
|
|
|
|
else if (auto const parent = files.front()->get_parent(); parent != nullptr)
|
2022-10-08 22:50:03 +00:00
|
|
|
{
|
2023-10-20 22:13:18 +00:00
|
|
|
gtr_pref_string_set(TR_KEY_open_dialog_dir, parent->get_path());
|
2022-10-08 22:50:03 +00:00
|
|
|
}
|
2021-10-18 20:22:31 +00:00
|
|
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
|
|
|
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)
|
2024-01-22 00:24:28 +00:00
|
|
|
: Gtk::FileChooserNative(_("Open a Torrent"), parent, TR_GTK_FILE_CHOOSER_ACTION(OPEN), _("_Open"), _("_Cancel"))
|
2008-03-18 01:22:11 +00:00
|
|
|
{
|
2022-01-18 20:16:25 +00:00
|
|
|
set_modal(true);
|
|
|
|
|
2021-10-18 20:22:31 +00:00
|
|
|
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
|
|
|
{
|
2022-10-08 22:50:03 +00:00
|
|
|
IF_GTKMM4(set_current_folder, set_current_folder_file)(Gio::File::create_for_path(folder));
|
2017-04-19 12:04:45 +00:00
|
|
|
}
|
|
|
|
|
2022-11-15 00:53:12 +00:00
|
|
|
add_choice(std::string(ShowOptionsDialogChoice), _("Show options dialog"));
|
|
|
|
set_choice(std::string(ShowOptionsDialogChoice), gtr_pref_flag_get(TR_KEY_show_options_window) ? "true" : "false");
|
2008-03-18 01:22:11 +00:00
|
|
|
}
|
2008-09-23 19:11:04 +00:00
|
|
|
|
2009-11-22 16:20:22 +00:00
|
|
|
/***
|
|
|
|
****
|
|
|
|
***/
|
|
|
|
|
2022-09-07 22:25:04 +00:00
|
|
|
void TorrentUrlChooserDialog::onOpenURLResponse(int response, Gtk::Entry const& entry, Glib::RefPtr<Session> const& core)
|
2009-11-22 16:20:22 +00:00
|
|
|
{
|
|
|
|
|
2022-09-10 13:19:54 +00:00
|
|
|
if (response == TR_GTK_RESPONSE_TYPE(CANCEL))
|
2009-11-22 16:20:22 +00:00
|
|
|
{
|
2022-10-08 22:50:03 +00:00
|
|
|
close();
|
2022-02-13 04:16:55 +00:00
|
|
|
}
|
2022-09-10 13:19:54 +00:00
|
|
|
else if (response == TR_GTK_RESPONSE_TYPE(ACCEPT))
|
2022-02-13 04:16:55 +00:00
|
|
|
{
|
2022-09-07 22:25:04 +00:00
|
|
|
auto const url = gtr_str_strip(entry.get_text());
|
2013-07-20 16:19:15 +00:00
|
|
|
|
2022-02-13 04:16:55 +00:00
|
|
|
if (url.empty())
|
2013-07-20 16:19:15 +00:00
|
|
|
{
|
2022-02-13 04:16:55 +00:00
|
|
|
return;
|
2009-11-22 16:20:22 +00:00
|
|
|
}
|
|
|
|
|
2022-02-13 04:16:55 +00:00
|
|
|
if (core->add_from_url(url))
|
|
|
|
{
|
2022-10-08 22:50:03 +00:00
|
|
|
close();
|
2022-02-13 04:16:55 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
gtr_unrecognized_url_dialog(*this, url);
|
|
|
|
}
|
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
|
|
|
{
|
2022-09-07 22:25:04 +00:00
|
|
|
auto const builder = Gtk::Builder::create_from_resource(gtr_get_full_resource_path("TorrentUrlChooserDialog.ui"));
|
|
|
|
return std::unique_ptr<TorrentUrlChooserDialog>(
|
|
|
|
gtr_get_widget_derived<TorrentUrlChooserDialog>(builder, "TorrentUrlChooserDialog", parent, core));
|
2021-10-18 20:22:31 +00:00
|
|
|
}
|
|
|
|
|
2022-09-07 22:25:04 +00:00
|
|
|
TorrentUrlChooserDialog::TorrentUrlChooserDialog(
|
|
|
|
BaseObjectType* cast_item,
|
|
|
|
Glib::RefPtr<Gtk::Builder> const& builder,
|
|
|
|
Gtk::Window& parent,
|
|
|
|
Glib::RefPtr<Session> const& core)
|
|
|
|
: Gtk::Dialog(cast_item)
|
2009-11-22 16:20:22 +00:00
|
|
|
{
|
2022-09-07 22:25:04 +00:00
|
|
|
set_transient_for(parent);
|
2017-04-19 12:04:45 +00:00
|
|
|
|
2022-09-07 22:25:04 +00:00
|
|
|
auto* const e = gtr_get_widget<Gtk::Entry>(builder, "url_entry");
|
2021-10-18 20:22:31 +00:00
|
|
|
gtr_paste_clipboard_url_into_entry(*e);
|
2017-04-19 12:04:45 +00:00
|
|
|
|
2022-09-07 22:25:04 +00:00
|
|
|
signal_response().connect([this, e, core](int response) { onOpenURLResponse(response, *e, core); });
|
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
|
|
|
|
{
|
2022-09-10 13:19:54 +00:00
|
|
|
get_widget_for_response(TR_GTK_RESPONSE_TYPE(ACCEPT))->grab_focus();
|
2017-04-19 12:04:45 +00:00
|
|
|
}
|
2009-11-22 16:20:22 +00:00
|
|
|
}
|