2022-06-28 14:07:12 +00:00
|
|
|
// This file Copyright © 2005-2022 Transmission authors and contributors.
|
2022-01-20 18:27:56 +00:00
|
|
|
// It may be used under the MIT (SPDX: MIT) license.
|
|
|
|
// License text can be found in the licenses/ folder.
|
2006-07-16 19:39:23 +00:00
|
|
|
|
2022-12-26 21:13:21 +00:00
|
|
|
#include "Application.h"
|
2022-12-29 02:42:20 +00:00
|
|
|
#include "GtkCompat.h"
|
2022-12-26 21:13:21 +00:00
|
|
|
#include "Notify.h"
|
|
|
|
#include "Prefs.h"
|
|
|
|
#include "Utils.h"
|
|
|
|
|
|
|
|
#include <libtransmission/transmission.h>
|
|
|
|
#include <libtransmission/utils.h>
|
|
|
|
#include <libtransmission/version.h>
|
2010-12-23 22:31:28 +00:00
|
|
|
|
2022-12-27 01:43:20 +00:00
|
|
|
#include <giomm/file.h>
|
|
|
|
#include <giomm/init.h>
|
2021-10-31 21:04:31 +00:00
|
|
|
#include <glibmm/i18n.h>
|
2022-12-27 01:43:20 +00:00
|
|
|
#include <glibmm/init.h>
|
|
|
|
#include <glibmm/miscutils.h>
|
|
|
|
#include <glibmm/objectbase.h>
|
|
|
|
#include <glibmm/optioncontext.h>
|
|
|
|
#include <glibmm/optionentry.h>
|
|
|
|
#include <glibmm/optiongroup.h>
|
|
|
|
#include <glibmm/ustring.h>
|
|
|
|
#include <glibmm/wrap.h>
|
2021-10-18 20:22:31 +00:00
|
|
|
#include <gtkmm.h>
|
2006-07-16 19:39:23 +00:00
|
|
|
|
2022-10-15 16:13:50 +00:00
|
|
|
#include <fmt/core.h>
|
|
|
|
|
2022-12-26 21:13:21 +00:00
|
|
|
#include <clocale>
|
|
|
|
#include <cstdio>
|
|
|
|
#include <string>
|
|
|
|
#include <tuple>
|
2006-07-16 19:39:23 +00:00
|
|
|
|
2021-10-18 20:22:31 +00:00
|
|
|
namespace
|
|
|
|
{
|
2011-03-03 01:59:25 +00:00
|
|
|
|
2021-12-14 08:43:27 +00:00
|
|
|
auto const* const AppConfigDirName = "transmission";
|
|
|
|
auto const* const AppTranslationDomainName = "transmission-gtk";
|
|
|
|
auto const* const AppName = "transmission-gtk";
|
|
|
|
|
2021-10-31 21:04:31 +00:00
|
|
|
Glib::OptionEntry create_option_entry(Glib::ustring const& long_name, gchar short_name, Glib::ustring const& description)
|
2011-03-03 01:59:25 +00:00
|
|
|
{
|
2021-10-31 21:04:31 +00:00
|
|
|
Glib::OptionEntry entry;
|
|
|
|
entry.set_long_name(long_name);
|
|
|
|
entry.set_short_name(short_name);
|
|
|
|
entry.set_description(description);
|
|
|
|
return entry;
|
2011-03-03 01:59:25 +00:00
|
|
|
}
|
|
|
|
|
2021-10-18 20:22:31 +00:00
|
|
|
} // namespace
|
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
int main(int argc, char** argv)
|
2007-02-19 22:09:05 +00:00
|
|
|
{
|
2017-04-19 12:04:45 +00:00
|
|
|
/* init i18n */
|
2022-11-15 00:53:12 +00:00
|
|
|
std::ignore = std::setlocale(LC_ALL, "");
|
2021-12-14 08:43:27 +00:00
|
|
|
bindtextdomain(AppTranslationDomainName, TRANSMISSIONLOCALEDIR);
|
|
|
|
bind_textdomain_codeset(AppTranslationDomainName, "UTF-8");
|
|
|
|
textdomain(AppTranslationDomainName);
|
2017-04-19 12:04:45 +00:00
|
|
|
|
|
|
|
/* init glib/gtk */
|
2022-10-08 22:50:03 +00:00
|
|
|
Gio::init();
|
2021-10-18 20:22:31 +00:00
|
|
|
Glib::init();
|
|
|
|
Glib::set_application_name(_("Transmission"));
|
|
|
|
|
2022-10-08 22:50:03 +00:00
|
|
|
/* Workaround "..." */
|
|
|
|
Gio::File::create_for_path(".");
|
|
|
|
Glib::wrap_register(
|
|
|
|
g_type_from_name("GLocalFile"),
|
2022-11-13 17:36:16 +00:00
|
|
|
[](GObject* object) -> Glib::ObjectBase* { return new Gio::File(G_FILE(object)); });
|
2022-10-08 22:50:03 +00:00
|
|
|
g_type_ensure(Gio::File::get_type());
|
|
|
|
|
2021-10-18 20:22:31 +00:00
|
|
|
/* default settings */
|
2021-12-14 08:43:27 +00:00
|
|
|
std::string config_dir;
|
2021-10-18 20:22:31 +00:00
|
|
|
bool show_version = false;
|
|
|
|
bool start_paused = false;
|
|
|
|
bool is_iconified = false;
|
2017-04-19 12:04:45 +00:00
|
|
|
|
|
|
|
/* parse the command line */
|
2021-10-18 20:22:31 +00:00
|
|
|
auto const config_dir_option = create_option_entry("config-dir", 'g', _("Where to look for configuration files"));
|
|
|
|
auto const paused_option = create_option_entry("paused", 'p', _("Start with all torrents paused"));
|
|
|
|
auto const minimized_option = create_option_entry("minimized", 'm', _("Start minimized in notification area"));
|
|
|
|
auto const version_option = create_option_entry("version", 'v', _("Show version number and exit"));
|
|
|
|
|
|
|
|
Glib::OptionGroup main_group({}, {});
|
|
|
|
main_group.add_entry_filename(config_dir_option, config_dir);
|
|
|
|
main_group.add_entry(paused_option, start_paused);
|
|
|
|
main_group.add_entry(minimized_option, is_iconified);
|
|
|
|
main_group.add_entry(version_option, show_version);
|
2017-04-19 12:04:45 +00:00
|
|
|
|
2021-10-18 20:22:31 +00:00
|
|
|
Glib::OptionContext option_context(_("[torrent files or urls]"));
|
|
|
|
option_context.set_main_group(main_group);
|
2022-10-08 22:50:03 +00:00
|
|
|
#if !GTKMM_CHECK_VERSION(4, 0, 0)
|
2021-10-18 20:22:31 +00:00
|
|
|
Gtk::Main::add_gtk_option_group(option_context);
|
2022-10-08 22:50:03 +00:00
|
|
|
#endif
|
2021-10-18 20:22:31 +00:00
|
|
|
option_context.set_translation_domain(GETTEXT_PACKAGE);
|
|
|
|
|
|
|
|
try
|
|
|
|
{
|
|
|
|
option_context.parse(argc, argv);
|
|
|
|
}
|
|
|
|
catch (Glib::OptionError const& e)
|
2017-04-19 12:04:45 +00:00
|
|
|
{
|
2022-10-15 16:13:50 +00:00
|
|
|
fmt::print(stderr, "{}\n", TR_GLIB_EXCEPTION_WHAT(e));
|
|
|
|
fmt::print(
|
|
|
|
stderr,
|
|
|
|
_("Run '{program} --help' to see a full list of available command line options.\n"),
|
2022-11-13 17:36:16 +00:00
|
|
|
fmt::arg("program", *argv));
|
2017-04-19 12:04:45 +00:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* handle the trivial "version" option */
|
|
|
|
if (show_version)
|
|
|
|
{
|
2022-10-15 16:13:50 +00:00
|
|
|
fmt::print(stderr, "{} {}\n", AppName, LONG_VERSION_STRING);
|
2017-04-19 12:04:45 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* init the unit formatters */
|
|
|
|
tr_formatter_mem_init(mem_K, _(mem_K_str), _(mem_M_str), _(mem_G_str), _(mem_T_str));
|
|
|
|
tr_formatter_size_init(disk_K, _(disk_K_str), _(disk_M_str), _(disk_G_str), _(disk_T_str));
|
|
|
|
tr_formatter_speed_init(speed_K, _(speed_K_str), _(speed_M_str), _(speed_G_str), _(speed_T_str));
|
|
|
|
|
|
|
|
/* set up the config dir */
|
2022-07-23 01:10:02 +00:00
|
|
|
if (std::empty(config_dir))
|
2021-12-14 08:43:27 +00:00
|
|
|
{
|
2022-08-17 00:28:57 +00:00
|
|
|
config_dir = tr_getDefaultConfigDir(AppConfigDirName);
|
2021-12-14 08:43:27 +00:00
|
|
|
}
|
|
|
|
|
2021-10-18 20:22:31 +00:00
|
|
|
gtr_pref_init(config_dir);
|
|
|
|
g_mkdir_with_parents(config_dir.c_str(), 0755);
|
2017-04-19 12:04:45 +00:00
|
|
|
|
|
|
|
/* init notifications */
|
|
|
|
gtr_notify_init();
|
|
|
|
|
|
|
|
/* init the application for the specified config dir */
|
2021-10-18 20:22:31 +00:00
|
|
|
return Application(config_dir, start_paused, is_iconified).run(argc, argv);
|
2007-02-19 22:09:05 +00:00
|
|
|
}
|