2006-08-13 00:26:52 +00:00
|
|
|
/******************************************************************************
|
2011-01-19 13:48:47 +00:00
|
|
|
* Copyright (c) Transmission authors and contributors
|
2006-08-13 00:26:52 +00:00
|
|
|
*
|
|
|
|
* Permission is hereby granted, free of charge, to any person obtaining a
|
|
|
|
* copy of this software and associated documentation files (the "Software"),
|
|
|
|
* to deal in the Software without restriction, including without limitation
|
|
|
|
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
|
|
|
* and/or sell copies of the Software, and to permit persons to whom the
|
|
|
|
* Software is furnished to do so, subject to the following conditions:
|
|
|
|
*
|
|
|
|
* The above copyright notice and this permission notice shall be included in
|
|
|
|
* all copies or substantial portions of the Software.
|
|
|
|
*
|
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
|
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
|
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
|
|
|
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
|
|
|
* DEALINGS IN THE SOFTWARE.
|
|
|
|
*****************************************************************************/
|
2006-07-16 19:39:23 +00:00
|
|
|
|
2021-10-18 20:22:31 +00:00
|
|
|
#include <string>
|
2010-12-23 22:31:28 +00:00
|
|
|
|
2021-10-18 20:22:31 +00:00
|
|
|
#include <glibmm.h>
|
2021-10-31 21:04:31 +00:00
|
|
|
#include <glibmm/i18n.h>
|
2021-10-18 20:22:31 +00:00
|
|
|
#include <gtkmm.h>
|
2006-07-16 19:39:23 +00:00
|
|
|
|
2008-09-01 04:47:02 +00:00
|
|
|
#include <libtransmission/transmission.h>
|
|
|
|
#include <libtransmission/utils.h>
|
2008-05-06 19:27:42 +00:00
|
|
|
#include <libtransmission/version.h>
|
|
|
|
|
2021-11-01 00:11:23 +00:00
|
|
|
#include "Application.h"
|
|
|
|
#include "Notify.h"
|
|
|
|
#include "Prefs.h"
|
|
|
|
#include "Utils.h"
|
2006-07-16 19:39:23 +00:00
|
|
|
|
2010-08-05 13:24:46 +00:00
|
|
|
#define MY_CONFIG_NAME "transmission"
|
|
|
|
#define MY_READABLE_NAME "transmission-gtk"
|
2008-12-13 23:17:36 +00:00
|
|
|
|
2021-10-18 20:22:31 +00:00
|
|
|
namespace
|
|
|
|
{
|
2011-03-03 01:59:25 +00:00
|
|
|
|
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 */
|
|
|
|
setlocale(LC_ALL, "");
|
|
|
|
bindtextdomain(MY_READABLE_NAME, TRANSMISSIONLOCALEDIR);
|
|
|
|
bind_textdomain_codeset(MY_READABLE_NAME, "UTF-8");
|
|
|
|
textdomain(MY_READABLE_NAME);
|
|
|
|
|
|
|
|
/* init glib/gtk */
|
2021-10-18 20:22:31 +00:00
|
|
|
Glib::init();
|
|
|
|
Glib::set_application_name(_("Transmission"));
|
|
|
|
|
|
|
|
/* default settings */
|
|
|
|
std::string config_dir = tr_getDefaultConfigDir(MY_CONFIG_NAME);
|
|
|
|
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);
|
|
|
|
Gtk::Main::add_gtk_option_group(option_context);
|
|
|
|
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
|
|
|
{
|
2021-10-18 20:22:31 +00:00
|
|
|
g_print(_("%s\nRun '%s --help' to see a full list of available command line options.\n"), e.what().c_str(), argv[0]);
|
2017-04-19 12:04:45 +00:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* handle the trivial "version" option */
|
|
|
|
if (show_version)
|
|
|
|
{
|
|
|
|
fprintf(stderr, "%s %s\n", MY_READABLE_NAME, LONG_VERSION_STRING);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2021-10-18 20:22:31 +00:00
|
|
|
Gtk::Window::set_default_icon_name(MY_CONFIG_NAME);
|
2017-04-19 12:04:45 +00:00
|
|
|
|
|
|
|
/* 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 */
|
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
|
|
|
}
|