mirror of
https://github.com/telegramdesktop/tdesktop
synced 2025-01-15 19:55:18 +00:00
Don't use QLibrary for glib
This commit is contained in:
parent
806f2e0b50
commit
4922768086
@ -1146,15 +1146,16 @@ elseif (APPLE)
|
||||
elseif (LINUX)
|
||||
if (NOT TDESKTOP_DISABLE_GTK_INTEGRATION)
|
||||
find_package(PkgConfig REQUIRED)
|
||||
|
||||
pkg_search_module(GTK REQUIRED gtk+-2.0 gtk+-3.0)
|
||||
target_include_directories(Telegram PRIVATE ${GTK_INCLUDE_DIRS})
|
||||
target_compile_options(Telegram PRIVATE -Wno-register)
|
||||
|
||||
if (DESKTOP_APP_USE_PACKAGED)
|
||||
find_library(X11_LIBRARY X11)
|
||||
target_link_libraries(Telegram PRIVATE ${X11_LIBRARY})
|
||||
endif()
|
||||
target_include_directories(Telegram PRIVATE ${GTK_INCLUDE_DIRS})
|
||||
target_link_libraries(Telegram
|
||||
PRIVATE
|
||||
X11
|
||||
gobject-2.0
|
||||
glib-2.0
|
||||
)
|
||||
target_compile_options(Telegram PRIVATE -Wno-register)
|
||||
endif()
|
||||
endif()
|
||||
|
||||
|
@ -263,11 +263,11 @@ bool Get(
|
||||
namespace internal {
|
||||
|
||||
QGtkDialog::QGtkDialog(GtkWidget *gtkWidget) : gtkWidget(gtkWidget) {
|
||||
Libs::g_signal_connect_swapped_helper(Libs::g_object_cast(gtkWidget), "response", GCallback(onResponse), this);
|
||||
Libs::g_signal_connect_helper(Libs::g_object_cast(gtkWidget), "delete-event", GCallback(Libs::gtk_widget_hide_on_delete), nullptr);
|
||||
g_signal_connect_swapped(G_OBJECT(gtkWidget), "response", G_CALLBACK(onResponse), this);
|
||||
g_signal_connect(G_OBJECT(gtkWidget), "delete-event", G_CALLBACK(Libs::gtk_widget_hide_on_delete), nullptr);
|
||||
if (PreviewSupported()) {
|
||||
_preview = Libs::gtk_image_new();
|
||||
Libs::g_signal_connect_swapped_helper(Libs::g_object_cast(gtkWidget), "update-preview", GCallback(onUpdatePreview), this);
|
||||
g_signal_connect_swapped(G_OBJECT(gtkWidget), "update-preview", G_CALLBACK(onUpdatePreview), this);
|
||||
Libs::gtk_file_chooser_set_preview_widget(Libs::gtk_file_chooser_cast(gtkWidget), _preview);
|
||||
}
|
||||
}
|
||||
@ -339,17 +339,17 @@ void QGtkDialog::onUpdatePreview(QGtkDialog* dialog) {
|
||||
// this may hang. See https://crbug.com/534754.
|
||||
struct stat stat_buf;
|
||||
if (stat(filename, &stat_buf) != 0 || !S_ISREG(stat_buf.st_mode)) {
|
||||
Libs::g_free(filename);
|
||||
g_free(filename);
|
||||
Libs::gtk_file_chooser_set_preview_widget_active(Libs::gtk_file_chooser_cast(dialog->gtkWidget), false);
|
||||
return;
|
||||
}
|
||||
|
||||
// This will preserve the image's aspect ratio.
|
||||
auto pixbuf = Libs::gdk_pixbuf_new_from_file_at_size(filename, kPreviewWidth, kPreviewHeight, nullptr);
|
||||
Libs::g_free(filename);
|
||||
g_free(filename);
|
||||
if (pixbuf) {
|
||||
Libs::gtk_image_set_from_pixbuf(Libs::gtk_image_cast(dialog->_preview), pixbuf);
|
||||
Libs::g_object_unref(pixbuf);
|
||||
g_object_unref(pixbuf);
|
||||
}
|
||||
Libs::gtk_file_chooser_set_preview_widget_active(Libs::gtk_file_chooser_cast(dialog->gtkWidget), pixbuf ? true : false);
|
||||
}
|
||||
@ -396,8 +396,8 @@ GtkFileDialog::GtkFileDialog(QWidget *parent, const QString &caption, const QStr
|
||||
connect(d.data(), SIGNAL(accept()), this, SLOT(onAccepted()));
|
||||
connect(d.data(), SIGNAL(reject()), this, SLOT(onRejected()));
|
||||
|
||||
Libs::g_signal_connect_helper(Libs::gtk_file_chooser_cast(d->gtkDialog()), "selection-changed", G_CALLBACK(onSelectionChanged), this);
|
||||
Libs::g_signal_connect_swapped_helper(Libs::gtk_file_chooser_cast(d->gtkDialog()), "current-folder-changed", G_CALLBACK(onCurrentFolderChanged), this);
|
||||
g_signal_connect(Libs::gtk_file_chooser_cast(d->gtkDialog()), "selection-changed", G_CALLBACK(onSelectionChanged), this);
|
||||
g_signal_connect_swapped(Libs::gtk_file_chooser_cast(d->gtkDialog()), "current-folder-changed", G_CALLBACK(onCurrentFolderChanged), this);
|
||||
}
|
||||
|
||||
GtkFileDialog::~GtkFileDialog() {
|
||||
@ -491,7 +491,7 @@ QDir GtkFileDialog::directory() const {
|
||||
gchar *folder = Libs::gtk_file_chooser_get_current_folder(Libs::gtk_file_chooser_cast(gtkDialog));
|
||||
if (folder) {
|
||||
ret = QString::fromUtf8(folder);
|
||||
Libs::g_free(folder);
|
||||
g_free(folder);
|
||||
}
|
||||
return QDir(ret);
|
||||
}
|
||||
@ -512,7 +512,7 @@ QStringList GtkFileDialog::selectedFiles() const {
|
||||
GSList *filenames = Libs::gtk_file_chooser_get_filenames(Libs::gtk_file_chooser_cast(gtkDialog));
|
||||
for (GSList *it = filenames; it; it = it->next)
|
||||
selection += QString::fromUtf8((const char*)it->data);
|
||||
Libs::g_slist_free(filenames);
|
||||
g_slist_free(filenames);
|
||||
return selection;
|
||||
}
|
||||
|
||||
|
@ -116,19 +116,6 @@ bool setupGtkBase(QLibrary &lib_gtk) {
|
||||
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_type_check_instance_cast", g_type_check_instance_cast)) return false;
|
||||
if (!load(lib_gtk, "g_type_check_instance_is_a", g_type_check_instance_is_a)) return false;
|
||||
if (!load(lib_gtk, "g_signal_connect_data", g_signal_connect_data)) return false;
|
||||
|
||||
if (!load(lib_gtk, "g_object_get", g_object_get)) return false;
|
||||
if (!load(lib_gtk, "g_object_unref", g_object_unref)) return false;
|
||||
if (!load(lib_gtk, "g_free", g_free)) return false;
|
||||
|
||||
if (!load(lib_gtk, "g_slist_free", g_slist_free)) return false;
|
||||
|
||||
if (!load(lib_gtk, "g_log_set_handler", g_log_set_handler)) return false;
|
||||
if (!load(lib_gtk, "g_log_default_handler", g_log_default_handler)) return false;
|
||||
|
||||
if (!load(lib_gtk, "gdk_atom_intern", gdk_atom_intern)) return false;
|
||||
|
||||
if (load(lib_gtk, "gdk_set_allowed_backends", gdk_set_allowed_backends)) {
|
||||
@ -218,9 +205,6 @@ 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_type_check_instance_is_a g_type_check_instance_is_a = nullptr;
|
||||
f_g_signal_connect_data g_signal_connect_data = nullptr;
|
||||
f_gdk_atom_intern gdk_atom_intern = nullptr;
|
||||
f_gdk_pixbuf_new_from_file_at_size gdk_pixbuf_new_from_file_at_size = nullptr;
|
||||
f_gdk_pixbuf_get_has_alpha gdk_pixbuf_get_has_alpha = nullptr;
|
||||
@ -228,12 +212,6 @@ f_gdk_pixbuf_get_pixels gdk_pixbuf_get_pixels = nullptr;
|
||||
f_gdk_pixbuf_get_width gdk_pixbuf_get_width = nullptr;
|
||||
f_gdk_pixbuf_get_height gdk_pixbuf_get_height = nullptr;
|
||||
f_gdk_pixbuf_get_rowstride gdk_pixbuf_get_rowstride = nullptr;
|
||||
f_g_object_get g_object_get = nullptr;
|
||||
f_g_object_unref g_object_unref = nullptr;
|
||||
f_g_free g_free = nullptr;
|
||||
f_g_slist_free g_slist_free = nullptr;
|
||||
f_g_log_set_handler g_log_set_handler = nullptr;
|
||||
f_g_log_default_handler g_log_default_handler = nullptr;
|
||||
#endif // !TDESKTOP_DISABLE_GTK_INTEGRATION
|
||||
|
||||
void start() {
|
||||
|
@ -167,9 +167,6 @@ extern f_gdk_window_set_modal_hint gdk_window_set_modal_hint;
|
||||
typedef void (*f_gdk_window_focus)(GdkWindow *window, guint32 timestamp);
|
||||
extern f_gdk_window_focus gdk_window_focus;
|
||||
|
||||
typedef GTypeInstance* (*f_g_type_check_instance_cast)(GTypeInstance *instance, GType iface_type);
|
||||
extern f_g_type_check_instance_cast g_type_check_instance_cast;
|
||||
|
||||
template <typename Result, typename Object>
|
||||
inline Result *g_type_cic_helper(Object *instance, GType iface_type) {
|
||||
return reinterpret_cast<Result*>(g_type_check_instance_cast(reinterpret_cast<GTypeInstance*>(instance), iface_type));
|
||||
@ -183,11 +180,6 @@ inline GtkDialog *gtk_dialog_cast(Object *obj) {
|
||||
return g_type_cic_helper<GtkDialog, Object>(obj, gtk_dialog_get_type());
|
||||
}
|
||||
|
||||
template <typename Object>
|
||||
inline GObject *g_object_cast(Object *obj) {
|
||||
return g_type_cic_helper<GObject, Object>(obj, G_TYPE_OBJECT);
|
||||
}
|
||||
|
||||
typedef GType (*f_gtk_file_chooser_get_type)(void) G_GNUC_CONST;
|
||||
extern f_gtk_file_chooser_get_type gtk_file_chooser_get_type;
|
||||
|
||||
@ -220,9 +212,6 @@ inline GtkWindow *gtk_window_cast(Object *obj) {
|
||||
return g_type_cic_helper<GtkWindow, Object>(obj, gtk_window_get_type());
|
||||
}
|
||||
|
||||
typedef gboolean (*f_g_type_check_instance_is_a)(GTypeInstance *instance, GType iface_type);
|
||||
extern f_g_type_check_instance_is_a g_type_check_instance_is_a;
|
||||
|
||||
template <typename Object>
|
||||
inline bool g_type_cit_helper(Object *instance, GType iface_type) {
|
||||
if (!instance) return false;
|
||||
@ -237,17 +226,6 @@ inline bool g_type_cit_helper(Object *instance, GType iface_type) {
|
||||
typedef gint (*f_gtk_dialog_run)(GtkDialog *dialog);
|
||||
extern f_gtk_dialog_run gtk_dialog_run;
|
||||
|
||||
typedef gulong (*f_g_signal_connect_data)(gpointer instance, const gchar *detailed_signal, GCallback c_handler, gpointer data, GClosureNotify destroy_data, GConnectFlags connect_flags);
|
||||
extern f_g_signal_connect_data g_signal_connect_data;
|
||||
|
||||
inline gulong g_signal_connect_helper(gpointer instance, const gchar *detailed_signal, GCallback c_handler, gpointer data, GClosureNotify destroy_data = nullptr) {
|
||||
return g_signal_connect_data(instance, detailed_signal, c_handler, data, destroy_data, (GConnectFlags)0);
|
||||
}
|
||||
|
||||
inline gulong g_signal_connect_swapped_helper(gpointer instance, const gchar *detailed_signal, GCallback c_handler, gpointer data, GClosureNotify destroy_data = nullptr) {
|
||||
return g_signal_connect_data(instance, detailed_signal, c_handler, data, destroy_data, G_CONNECT_SWAPPED);
|
||||
}
|
||||
|
||||
typedef GdkAtom (*f_gdk_atom_intern)(const gchar *atom_name, gboolean only_if_exists);
|
||||
extern f_gdk_atom_intern gdk_atom_intern;
|
||||
|
||||
@ -268,24 +246,6 @@ extern f_gdk_pixbuf_get_height gdk_pixbuf_get_height;
|
||||
|
||||
typedef int (*f_gdk_pixbuf_get_rowstride)(const GdkPixbuf *pixbuf);
|
||||
extern f_gdk_pixbuf_get_rowstride gdk_pixbuf_get_rowstride;
|
||||
|
||||
typedef void (*f_g_object_get)(gpointer object, const gchar *first_property_name, ...) G_GNUC_NULL_TERMINATED;
|
||||
extern f_g_object_get g_object_get;
|
||||
|
||||
typedef void (*f_g_object_unref)(gpointer object);
|
||||
extern f_g_object_unref g_object_unref;
|
||||
|
||||
typedef void (*f_g_free)(gpointer mem);
|
||||
extern f_g_free g_free;
|
||||
|
||||
typedef void (*f_g_slist_free)(GSList *list);
|
||||
extern f_g_slist_free g_slist_free;
|
||||
|
||||
typedef guint (*f_g_log_set_handler)(const gchar *log_domain, GLogLevelFlags log_levels, GLogFunc log_func, gpointer user_data);
|
||||
extern f_g_log_set_handler g_log_set_handler;
|
||||
|
||||
typedef void (*f_g_log_default_handler)(const gchar *log_domain, GLogLevelFlags log_level, const gchar *message, gpointer unused_data);
|
||||
extern f_g_log_default_handler g_log_default_handler;
|
||||
#endif // !TDESKTOP_DISABLE_GTK_INTEGRATION
|
||||
|
||||
} // namespace Libs
|
||||
|
@ -531,8 +531,7 @@ bool GtkClipboardSupported() {
|
||||
&& (Libs::gdk_pixbuf_get_height != nullptr)
|
||||
&& (Libs::gdk_pixbuf_get_rowstride != nullptr)
|
||||
&& (Libs::gdk_pixbuf_get_has_alpha != nullptr)
|
||||
&& (Libs::gdk_atom_intern != nullptr)
|
||||
&& (Libs::g_object_unref != nullptr);
|
||||
&& (Libs::gdk_atom_intern != nullptr);
|
||||
}
|
||||
|
||||
QImage GetImageFromClipboard() {
|
||||
@ -561,7 +560,7 @@ QImage GetImageFromClipboard() {
|
||||
? QImage::Format_RGBA8888
|
||||
: QImage::Format_RGB888).copy();
|
||||
|
||||
Libs::g_object_unref(img);
|
||||
g_object_unref(img);
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user