mirror of
https://github.com/kotatogram/kotatogram-desktop
synced 2025-08-31 14:45:14 +00:00
Using GTK file dialog when it is available.
Should work both with GTK 2 and GTK 3.
This commit is contained in:
@@ -21,6 +21,8 @@ Copyright (c) 2014-2016 John Preston, https://desktop.telegram.org
|
||||
#include "stdafx.h"
|
||||
#include "platform/linux/linux_libs.h"
|
||||
|
||||
#include "platform/linux/linux_gdk_helper.h"
|
||||
|
||||
namespace Platform {
|
||||
namespace Libs {
|
||||
namespace {
|
||||
@@ -42,27 +44,59 @@ bool loadLibrary(QLibrary &lib, const char *name, int version) {
|
||||
}
|
||||
|
||||
bool setupGtkBase(QLibrary &lib_gtk) {
|
||||
if (!load(lib_gtk, "gtk_init_check", gtk_init_check)) return false;
|
||||
if (!load(lib_gtk, "gtk_menu_new", gtk_menu_new)) return false;
|
||||
if (!load(lib_gtk, "gtk_menu_get_type", gtk_menu_get_type)) return false;
|
||||
if (!load(lib_gtk, "gtk_init_check", gtk_init_check)) return false;
|
||||
if (!load(lib_gtk, "gtk_menu_new", gtk_menu_new)) return false;
|
||||
if (!load(lib_gtk, "gtk_menu_get_type", gtk_menu_get_type)) return false;
|
||||
|
||||
if (!load(lib_gtk, "gtk_menu_item_new_with_label", gtk_menu_item_new_with_label)) return false;
|
||||
if (!load(lib_gtk, "gtk_menu_item_set_label", gtk_menu_item_set_label)) return false;
|
||||
if (!load(lib_gtk, "gtk_menu_shell_append", gtk_menu_shell_append)) return false;
|
||||
if (!load(lib_gtk, "gtk_menu_shell_get_type", gtk_menu_shell_get_type)) return false;
|
||||
if (!load(lib_gtk, "gtk_widget_show", gtk_widget_show)) return false;
|
||||
if (!load(lib_gtk, "gtk_widget_get_toplevel", gtk_widget_get_toplevel)) return false;
|
||||
if (!load(lib_gtk, "gtk_widget_get_visible", gtk_widget_get_visible)) return false;
|
||||
if (!load(lib_gtk, "gtk_widget_set_sensitive", gtk_widget_set_sensitive)) return false;
|
||||
if (!load(lib_gtk, "gtk_menu_item_new_with_label", gtk_menu_item_new_with_label)) return false;
|
||||
if (!load(lib_gtk, "gtk_menu_item_set_label", gtk_menu_item_set_label)) return false;
|
||||
if (!load(lib_gtk, "gtk_menu_shell_append", gtk_menu_shell_append)) return false;
|
||||
if (!load(lib_gtk, "gtk_menu_shell_get_type", gtk_menu_shell_get_type)) return false;
|
||||
if (!load(lib_gtk, "gtk_widget_show", gtk_widget_show)) return false;
|
||||
if (!load(lib_gtk, "gtk_widget_hide", gtk_widget_hide)) return false;
|
||||
if (!load(lib_gtk, "gtk_widget_get_toplevel", gtk_widget_get_toplevel)) return false;
|
||||
if (!load(lib_gtk, "gtk_widget_get_visible", gtk_widget_get_visible)) return false;
|
||||
if (!load(lib_gtk, "gtk_widget_get_window", gtk_widget_get_window)) return false;
|
||||
if (!load(lib_gtk, "gtk_widget_set_sensitive", gtk_widget_set_sensitive)) return false;
|
||||
if (!load(lib_gtk, "gtk_widget_realize", gtk_widget_realize)) return false;
|
||||
if (!load(lib_gtk, "gtk_widget_hide_on_delete", gtk_widget_hide_on_delete)) return false;
|
||||
if (!load(lib_gtk, "gtk_widget_destroy", gtk_widget_destroy)) return false;
|
||||
if (!load(lib_gtk, "gtk_clipboard_get", gtk_clipboard_get)) return false;
|
||||
if (!load(lib_gtk, "gtk_clipboard_store", gtk_clipboard_store)) return false;
|
||||
if (!load(lib_gtk, "gtk_file_chooser_dialog_new", gtk_file_chooser_dialog_new)) return false;
|
||||
if (!load(lib_gtk, "gtk_file_chooser_get_type", gtk_file_chooser_get_type)) return false;
|
||||
if (!load(lib_gtk, "gtk_file_chooser_set_current_folder", gtk_file_chooser_set_current_folder)) return false;
|
||||
if (!load(lib_gtk, "gtk_file_chooser_get_current_folder", gtk_file_chooser_get_current_folder)) return false;
|
||||
if (!load(lib_gtk, "gtk_file_chooser_set_current_name", gtk_file_chooser_set_current_name)) return false;
|
||||
if (!load(lib_gtk, "gtk_file_chooser_select_filename", gtk_file_chooser_select_filename)) return false;
|
||||
if (!load(lib_gtk, "gtk_file_chooser_get_filenames", gtk_file_chooser_get_filenames)) return false;
|
||||
if (!load(lib_gtk, "gtk_file_chooser_set_filter", gtk_file_chooser_set_filter)) return false;
|
||||
if (!load(lib_gtk, "gtk_file_chooser_get_filter", gtk_file_chooser_get_filter)) return false;
|
||||
if (!load(lib_gtk, "gtk_window_get_type", gtk_window_get_type)) return false;
|
||||
if (!load(lib_gtk, "gtk_window_set_title", gtk_window_set_title)) return false;
|
||||
if (!load(lib_gtk, "gtk_file_chooser_set_local_only", gtk_file_chooser_set_local_only)) return false;
|
||||
if (!load(lib_gtk, "gtk_file_chooser_set_action", gtk_file_chooser_set_action)) return false;
|
||||
if (!load(lib_gtk, "gtk_file_chooser_set_select_multiple", gtk_file_chooser_set_select_multiple)) return false;
|
||||
if (!load(lib_gtk, "gtk_file_chooser_set_do_overwrite_confirmation", gtk_file_chooser_set_do_overwrite_confirmation)) return false;
|
||||
if (!load(lib_gtk, "gtk_file_chooser_remove_filter", gtk_file_chooser_remove_filter)) return false;
|
||||
if (!load(lib_gtk, "gtk_file_filter_set_name", gtk_file_filter_set_name)) return false;
|
||||
if (!load(lib_gtk, "gtk_file_filter_add_pattern", gtk_file_filter_add_pattern)) return false;
|
||||
if (!load(lib_gtk, "gtk_file_chooser_add_filter", gtk_file_chooser_add_filter)) return false;
|
||||
if (!load(lib_gtk, "gtk_file_filter_new", gtk_file_filter_new)) return false;
|
||||
|
||||
if (!load(lib_gtk, "g_type_check_instance_cast", g_type_check_instance_cast)) return false;
|
||||
if (!load(lib_gtk, "g_signal_connect_data", g_signal_connect_data)) return false;
|
||||
if (!load(lib_gtk, "gdk_window_set_modal_hint", gdk_window_set_modal_hint)) return false;
|
||||
if (!load(lib_gtk, "gdk_window_focus", gdk_window_focus)) return false;
|
||||
if (!load(lib_gtk, "gtk_dialog_get_type", gtk_dialog_get_type)) return false;
|
||||
if (!load(lib_gtk, "gtk_dialog_run", gtk_dialog_run)) return false;
|
||||
|
||||
if (!load(lib_gtk, "g_object_ref_sink", g_object_ref_sink)) return false;
|
||||
if (!load(lib_gtk, "g_object_unref", g_object_unref)) return false;
|
||||
if (!load(lib_gtk, "g_type_check_instance_cast", g_type_check_instance_cast)) return false;
|
||||
if (!load(lib_gtk, "g_signal_connect_data", g_signal_connect_data)) return false;
|
||||
|
||||
DEBUG_LOG(("Library gtk functions loaded!"));
|
||||
if (!gtk_init_check(0, 0)) {
|
||||
if (!load(lib_gtk, "g_object_ref_sink", g_object_ref_sink)) return false;
|
||||
if (!load(lib_gtk, "g_object_unref", g_object_unref)) return false;
|
||||
|
||||
DEBUG_LOG(("Library gtk functions loaded!"));
|
||||
if (!gtk_init_check(0, 0)) {
|
||||
gtk_init_check = nullptr;
|
||||
DEBUG_LOG(("Failed to gtk_init_check(0, 0)!"));
|
||||
return false;
|
||||
@@ -73,12 +107,12 @@ bool setupGtkBase(QLibrary &lib_gtk) {
|
||||
}
|
||||
|
||||
bool setupAppIndicator(QLibrary &lib_indicator) {
|
||||
if (!load(lib_indicator, "app_indicator_new", app_indicator_new)) return false;
|
||||
if (!load(lib_indicator, "app_indicator_set_status", app_indicator_set_status)) return false;
|
||||
if (!load(lib_indicator, "app_indicator_set_menu", app_indicator_set_menu)) return false;
|
||||
if (!load(lib_indicator, "app_indicator_set_icon_full", app_indicator_set_icon_full)) return false;
|
||||
if (!load(lib_indicator, "app_indicator_new", app_indicator_new)) return false;
|
||||
if (!load(lib_indicator, "app_indicator_set_status", app_indicator_set_status)) return false;
|
||||
if (!load(lib_indicator, "app_indicator_set_menu", app_indicator_set_menu)) return false;
|
||||
if (!load(lib_indicator, "app_indicator_set_icon_full", app_indicator_set_icon_full)) return false;
|
||||
|
||||
DEBUG_LOG(("Library appindicator functions loaded!"));
|
||||
DEBUG_LOG(("Library appindicator functions loaded!"));
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -92,9 +126,43 @@ f_gtk_menu_item_set_label gtk_menu_item_set_label = nullptr;
|
||||
f_gtk_menu_shell_append gtk_menu_shell_append = nullptr;
|
||||
f_gtk_menu_shell_get_type gtk_menu_shell_get_type = nullptr;
|
||||
f_gtk_widget_show gtk_widget_show = nullptr;
|
||||
f_gtk_widget_hide gtk_widget_hide = nullptr;
|
||||
f_gtk_widget_get_toplevel gtk_widget_get_toplevel = nullptr;
|
||||
f_gtk_widget_get_visible gtk_widget_get_visible = nullptr;
|
||||
f_gtk_widget_get_window gtk_widget_get_window = nullptr;
|
||||
f_gtk_widget_set_sensitive gtk_widget_set_sensitive = nullptr;
|
||||
f_gtk_widget_realize gtk_widget_realize = nullptr;
|
||||
f_gtk_widget_hide_on_delete gtk_widget_hide_on_delete = nullptr;
|
||||
f_gtk_widget_destroy gtk_widget_destroy = nullptr;
|
||||
f_gtk_clipboard_get gtk_clipboard_get = nullptr;
|
||||
f_gtk_clipboard_store gtk_clipboard_store = nullptr;
|
||||
f_gtk_file_chooser_dialog_new gtk_file_chooser_dialog_new = nullptr;
|
||||
f_gtk_file_chooser_get_type gtk_file_chooser_get_type = nullptr;
|
||||
f_gtk_file_chooser_set_current_folder gtk_file_chooser_set_current_folder = nullptr;
|
||||
f_gtk_file_chooser_get_current_folder gtk_file_chooser_get_current_folder = nullptr;
|
||||
f_gtk_file_chooser_set_current_name gtk_file_chooser_set_current_name = nullptr;
|
||||
f_gtk_file_chooser_select_filename gtk_file_chooser_select_filename = nullptr;
|
||||
f_gtk_file_chooser_get_filenames gtk_file_chooser_get_filenames = nullptr;
|
||||
f_gtk_file_chooser_set_filter gtk_file_chooser_set_filter = nullptr;
|
||||
f_gtk_file_chooser_get_filter gtk_file_chooser_get_filter = nullptr;
|
||||
f_gtk_window_get_type gtk_window_get_type = nullptr;
|
||||
f_gtk_window_set_title gtk_window_set_title = nullptr;
|
||||
f_gtk_file_chooser_set_local_only gtk_file_chooser_set_local_only = nullptr;
|
||||
f_gtk_file_chooser_set_action gtk_file_chooser_set_action = nullptr;
|
||||
f_gtk_file_chooser_set_select_multiple gtk_file_chooser_set_select_multiple = nullptr;
|
||||
f_gtk_file_chooser_set_do_overwrite_confirmation gtk_file_chooser_set_do_overwrite_confirmation = nullptr;
|
||||
f_gtk_file_chooser_remove_filter gtk_file_chooser_remove_filter = nullptr;
|
||||
f_gtk_file_filter_set_name gtk_file_filter_set_name = nullptr;
|
||||
f_gtk_file_filter_add_pattern gtk_file_filter_add_pattern = nullptr;
|
||||
f_gtk_file_chooser_add_filter gtk_file_chooser_add_filter = nullptr;
|
||||
f_gtk_file_filter_new gtk_file_filter_new = nullptr;
|
||||
f_gtk_dialog_get_widget_for_response gtk_dialog_get_widget_for_response = nullptr;
|
||||
f_gtk_button_set_label gtk_button_set_label = nullptr;
|
||||
f_gtk_button_get_type gtk_button_get_type = nullptr;
|
||||
f_gdk_window_set_modal_hint gdk_window_set_modal_hint = nullptr;
|
||||
f_gdk_window_focus gdk_window_focus = nullptr;
|
||||
f_gtk_dialog_get_type gtk_dialog_get_type = nullptr;
|
||||
f_gtk_dialog_run gtk_dialog_run = nullptr;
|
||||
f_g_type_check_instance_cast g_type_check_instance_cast = nullptr;
|
||||
f_g_signal_connect_data g_signal_connect_data = nullptr;
|
||||
f_app_indicator_new app_indicator_new = nullptr;
|
||||
@@ -172,6 +240,12 @@ void start() {
|
||||
load(lib_gtk, "gtk_menu_popup", gtk_menu_popup);
|
||||
load(lib_gtk, "gtk_get_current_event_time", gtk_get_current_event_time);
|
||||
load(lib_gtk, "g_idle_add", g_idle_add);
|
||||
|
||||
internal::GdkHelperLoad(lib_gtk);
|
||||
|
||||
load(lib_gtk, "gtk_dialog_get_widget_for_response", gtk_dialog_get_widget_for_response);
|
||||
load(lib_gtk, "gtk_button_set_label", gtk_button_set_label);
|
||||
load(lib_gtk, "gtk_button_get_type", gtk_button_get_type);
|
||||
} else {
|
||||
LOG(("Could not load gtk-x11-2.0!"));
|
||||
}
|
||||
|
Reference in New Issue
Block a user