1
0
Fork 0
mirror of https://github.com/transmission/transmission synced 2025-03-04 10:38:13 +00:00
transmission/gtk/main.cc
Mike Gelfand c75c6bf5c8
Add support for GTK 4 (#3916)
* Make compact mode switch work for both GTK 3 and 4

* Implement GTK 4-specific view gesture handling

* Fix torrents view context menu on GTK 4

* Explicitly show/hide menubar on startup/teardown

* Switch from `Gtk::Pixbuf` to `Gio::Icon` for views

* Support GTK 4 exceptions based on `std::exception`

* Fix options menu setup with GTK 4

* Use `delete-event` (GTK 3) and `close-request` (GTK 4) signals to handle window clousure

* Add custom file chooser button implementation

GTK 4 drops FileChooserButton widget and suggests implementing it using
Button.

* Add helpers to set X11 hints with GTK 4

* Remove `HigWorkarea` class that's no longer used

* Make main menu shortcuts work with GTK 4

* Make drops work in main window and make dialog with GTK 4

* Remove unused `gtr_action_get_widget()` helper

* Fix text direction mark setup with GTK 4 (due to switch to enum class)

* Fix file tree font size calculation with GTK 4

* Fix crash during shutdown with GTK 4

* Switch from `RadioButton` to `CheckButton` for compatibility with GTK 4

* Fix opening files with GTK 4

* Rework torrent cell renderer to support both GTK 3 and 4

* Disable system tray icon support with GTK 4

* Fix windows positioning with GTK 4

* Fix focus event handling with GTK 4

* Adapt to tree model row/iterator changes in GTK 4

* Adapt to toplevel/root window changes in GTK 4

* Adapt to clipboard changes in GTK 4

* Adapt to icon/theme changes in GTK 4

* Adapt to file/path changes in GTK 4

* Random leftover fixes for GTK 4 compatibility

* Clean up unused code

* Move GTK 3 *.ui files into a subdirectory

* Add GTK 4 *.ui files

* Search for both GTK 3 and 4 during configuration
2022-10-09 01:50:03 +03:00

123 lines
3.9 KiB
C++

// This file Copyright © 2005-2022 Transmission authors and contributors.
// It may be used under the MIT (SPDX: MIT) license.
// License text can be found in the licenses/ folder.
#include <cstdio>
#include <string>
#include <glibmm.h>
#include <glibmm/i18n.h>
#include <gtkmm.h>
#include <libtransmission/transmission.h>
#include <libtransmission/utils.h>
#include <libtransmission/version.h>
#include "Application.h"
#include "Notify.h"
#include "Prefs.h"
#include "Utils.h"
namespace
{
auto const* const AppConfigDirName = "transmission";
auto const* const AppTranslationDomainName = "transmission-gtk";
auto const* const AppName = "transmission-gtk";
Glib::OptionEntry create_option_entry(Glib::ustring const& long_name, gchar short_name, Glib::ustring const& description)
{
Glib::OptionEntry entry;
entry.set_long_name(long_name);
entry.set_short_name(short_name);
entry.set_description(description);
return entry;
}
} // namespace
int main(int argc, char** argv)
{
/* init i18n */
setlocale(LC_ALL, "");
bindtextdomain(AppTranslationDomainName, TRANSMISSIONLOCALEDIR);
bind_textdomain_codeset(AppTranslationDomainName, "UTF-8");
textdomain(AppTranslationDomainName);
/* init glib/gtk */
Gio::init();
Glib::init();
Glib::set_application_name(_("Transmission"));
/* Workaround "..." */
Gio::File::create_for_path(".");
Glib::wrap_register(
g_type_from_name("GLocalFile"),
[](GObject* object) -> Glib::ObjectBase* { return new Gio::File((GFile*)object); });
g_type_ensure(Gio::File::get_type());
/* default settings */
std::string config_dir;
bool show_version = false;
bool start_paused = false;
bool is_iconified = false;
/* parse the command line */
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);
Glib::OptionContext option_context(_("[torrent files or urls]"));
option_context.set_main_group(main_group);
#if !GTKMM_CHECK_VERSION(4, 0, 0)
Gtk::Main::add_gtk_option_group(option_context);
#endif
option_context.set_translation_domain(GETTEXT_PACKAGE);
try
{
option_context.parse(argc, argv);
}
catch (Glib::OptionError const& e)
{
g_print(
_("%s\nRun '%s --help' to see a full list of available command line options.\n"),
TR_GLIB_EXCEPTION_WHAT(e),
argv[0]);
return 1;
}
/* handle the trivial "version" option */
if (show_version)
{
fprintf(stderr, "%s %s\n", AppName, LONG_VERSION_STRING);
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 */
if (std::empty(config_dir))
{
config_dir = tr_getDefaultConfigDir(AppConfigDirName);
}
gtr_pref_init(config_dir);
g_mkdir_with_parents(config_dir.c_str(), 0755);
/* init notifications */
gtr_notify_init();
/* init the application for the specified config dir */
return Application(config_dir, start_paused, is_iconified).run(argc, argv);
}