From 224c16ae310052b6fe9d4cdd9358af69960d6238 Mon Sep 17 00:00:00 2001 From: Gary Wang Date: Mon, 29 Jul 2019 16:19:31 +0800 Subject: [PATCH] refactor: move files inside different headers (#7) --- gio-qt/CMakeLists.txt | 41 +++++++++------ gio-qt/{ => include}/dgiofile.h | 0 gio-qt/{ => include}/dgiofileinfo.h | 0 gio-qt/{ => include}/dgiofileiterator.h | 0 gio-qt/{ => include}/dgiomount.h | 0 gio-qt/{ => include}/dgiomountoperation.h | 0 gio-qt/{ => include}/dgioutils.h | 0 gio-qt/{ => include}/dgiovolume.h | 0 gio-qt/{ => include}/dgiovolumemanager.h | 0 gio-qt/private/dgiohelper.cpp | 57 ++++++++++++++++++++ gio-qt/private/dgiohelper.h | 12 +++++ gio-qt/{ => source}/dgiofile.cpp | 0 gio-qt/{ => source}/dgiofileinfo.cpp | 0 gio-qt/{ => source}/dgiofileiterator.cpp | 0 gio-qt/{ => source}/dgiomount.cpp | 60 ++-------------------- gio-qt/{ => source}/dgiomountoperation.cpp | 0 gio-qt/{ => source}/dgioutils.cpp | 0 gio-qt/{ => source}/dgiovolume.cpp | 0 gio-qt/{ => source}/dgiovolumemanager.cpp | 0 19 files changed, 98 insertions(+), 72 deletions(-) rename gio-qt/{ => include}/dgiofile.h (100%) rename gio-qt/{ => include}/dgiofileinfo.h (100%) rename gio-qt/{ => include}/dgiofileiterator.h (100%) rename gio-qt/{ => include}/dgiomount.h (100%) rename gio-qt/{ => include}/dgiomountoperation.h (100%) rename gio-qt/{ => include}/dgioutils.h (100%) rename gio-qt/{ => include}/dgiovolume.h (100%) rename gio-qt/{ => include}/dgiovolumemanager.h (100%) create mode 100644 gio-qt/private/dgiohelper.cpp create mode 100644 gio-qt/private/dgiohelper.h rename gio-qt/{ => source}/dgiofile.cpp (100%) rename gio-qt/{ => source}/dgiofileinfo.cpp (100%) rename gio-qt/{ => source}/dgiofileiterator.cpp (100%) rename gio-qt/{ => source}/dgiomount.cpp (75%) rename gio-qt/{ => source}/dgiomountoperation.cpp (100%) rename gio-qt/{ => source}/dgioutils.cpp (100%) rename gio-qt/{ => source}/dgiovolume.cpp (100%) rename gio-qt/{ => source}/dgiovolumemanager.cpp (100%) diff --git a/gio-qt/CMakeLists.txt b/gio-qt/CMakeLists.txt index d0f4d2f..87be596 100644 --- a/gio-qt/CMakeLists.txt +++ b/gio-qt/CMakeLists.txt @@ -4,30 +4,36 @@ configure_file ("gio-qt.pc.in" "gio-qt.pc" @ONLY) set (QGIO_PUBLIC_HEADER_FILES - dgiovolumemanager.h - dgiomountoperation.h - dgiomount.h - dgiovolume.h - dgiofile.h - dgiofileinfo.h - dgioutils.h - dgiofileiterator.h + include/dgiovolumemanager.h + include/dgiomountoperation.h + include/dgiomount.h + include/dgiovolume.h + include/dgiofile.h + include/dgiofileinfo.h + include/dgioutils.h + include/dgiofileiterator.h +) + +set (QGIO_PRIVATE_HEADER_FILES + private/dgiohelper.h ) set (QGIO_PRIVATE_CPP_FILES - dgiovolumemanager.cpp - dgiomountoperation.cpp - dgiomount.cpp - dgiovolume.cpp - dgiofile.cpp - dgiofileinfo.cpp - dgioutils.cpp - dgiofileiterator.cpp + source/dgiovolumemanager.cpp + source/dgiomountoperation.cpp + source/dgiomount.cpp + source/dgiovolume.cpp + source/dgiofile.cpp + source/dgiofileinfo.cpp + source/dgioutils.cpp + source/dgiofileiterator.cpp + private/dgiohelper.cpp ) # Library add_library (gio-qt SHARED ${QGIO_PUBLIC_HEADER_FILES} + ${QGIO_PRIVATE_HEADER_FILES} ${QGIO_PRIVATE_CPP_FILES} ) @@ -40,8 +46,9 @@ set_target_properties( target_include_directories(gio-qt PRIVATE ${GIOMM_INCLUDE_DIRS} + ${CMAKE_CURRENT_LIST_DIR}/private PUBLIC - ${CMAKE_CURRENT_LIST_DIR} + ${CMAKE_CURRENT_LIST_DIR}/include ) target_link_libraries (gio-qt Qt5::Core ${GIOMM_LIBRARIES}) diff --git a/gio-qt/dgiofile.h b/gio-qt/include/dgiofile.h similarity index 100% rename from gio-qt/dgiofile.h rename to gio-qt/include/dgiofile.h diff --git a/gio-qt/dgiofileinfo.h b/gio-qt/include/dgiofileinfo.h similarity index 100% rename from gio-qt/dgiofileinfo.h rename to gio-qt/include/dgiofileinfo.h diff --git a/gio-qt/dgiofileiterator.h b/gio-qt/include/dgiofileiterator.h similarity index 100% rename from gio-qt/dgiofileiterator.h rename to gio-qt/include/dgiofileiterator.h diff --git a/gio-qt/dgiomount.h b/gio-qt/include/dgiomount.h similarity index 100% rename from gio-qt/dgiomount.h rename to gio-qt/include/dgiomount.h diff --git a/gio-qt/dgiomountoperation.h b/gio-qt/include/dgiomountoperation.h similarity index 100% rename from gio-qt/dgiomountoperation.h rename to gio-qt/include/dgiomountoperation.h diff --git a/gio-qt/dgioutils.h b/gio-qt/include/dgioutils.h similarity index 100% rename from gio-qt/dgioutils.h rename to gio-qt/include/dgioutils.h diff --git a/gio-qt/dgiovolume.h b/gio-qt/include/dgiovolume.h similarity index 100% rename from gio-qt/dgiovolume.h rename to gio-qt/include/dgiovolume.h diff --git a/gio-qt/dgiovolumemanager.h b/gio-qt/include/dgiovolumemanager.h similarity index 100% rename from gio-qt/dgiovolumemanager.h rename to gio-qt/include/dgiovolumemanager.h diff --git a/gio-qt/private/dgiohelper.cpp b/gio-qt/private/dgiohelper.cpp new file mode 100644 index 0000000..edddfac --- /dev/null +++ b/gio-qt/private/dgiohelper.cpp @@ -0,0 +1,57 @@ +#include "dgiohelper.h" + +#include + +#include + +using namespace Gio; + +namespace DGioPrivate { + +QStringList getThemedIconNames(Glib::RefPtr icon) +{ + QStringList iconNames; + + Glib::RefPtr themedIcon = Glib::RefPtr::cast_dynamic(icon); + + // due to https://gitlab.gnome.org/GNOME/glibmm/issues/50 we cannot use the glibmm way to get icon name. + // upstream already fixed the issue but we still need debian backport the patch so we can use it. + // see: https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=932950 + + // if (G_IS_THEMED_ICON(themedIcon->gobj()) ) { + // qDebug() << "Yes and"; + // } + + // if (themedIcon) { + // qDebug() << "Yes"; + // } + + if (themedIcon) { + char **names; + char **iter; + names = NULL; + g_object_get(G_THEMED_ICON(themedIcon->gobj()), "names", &names, NULL); + for (iter = names; *iter; iter++) { + iconNames.append(QString(*iter)); + } + g_strfreev(names); + return iconNames; + } + + // return {QStringList::fromStdList(themedIcon->get_names())}; + + // char* name = 0; + // g_object_get(G_OBJECT(themedIcon->gobj()), "name", &name, NULL); + // return {QString(name)}; + + // if (themedIcon) { + // auto ustring_names = themedIcon->get_names(); + //// for (const Glib::ustring &str : ustring_names) { + //// iconNames.append(QString::fromStdString(str.raw())); + //// } + // } + return iconNames; +} + +} + diff --git a/gio-qt/private/dgiohelper.h b/gio-qt/private/dgiohelper.h new file mode 100644 index 0000000..0c96f31 --- /dev/null +++ b/gio-qt/private/dgiohelper.h @@ -0,0 +1,12 @@ +#ifndef DGIOHELPER_H +#define DGIOHELPER_H + +#include + +#include + +namespace DGioPrivate { + QStringList getThemedIconNames(Glib::RefPtr icon); +} + +#endif // DGIOHELPER_H diff --git a/gio-qt/dgiofile.cpp b/gio-qt/source/dgiofile.cpp similarity index 100% rename from gio-qt/dgiofile.cpp rename to gio-qt/source/dgiofile.cpp diff --git a/gio-qt/dgiofileinfo.cpp b/gio-qt/source/dgiofileinfo.cpp similarity index 100% rename from gio-qt/dgiofileinfo.cpp rename to gio-qt/source/dgiofileinfo.cpp diff --git a/gio-qt/dgiofileiterator.cpp b/gio-qt/source/dgiofileiterator.cpp similarity index 100% rename from gio-qt/dgiofileiterator.cpp rename to gio-qt/source/dgiofileiterator.cpp diff --git a/gio-qt/dgiomount.cpp b/gio-qt/source/dgiomount.cpp similarity index 75% rename from gio-qt/dgiomount.cpp rename to gio-qt/source/dgiomount.cpp index db67b4e..2ce60e4 100644 --- a/gio-qt/dgiomount.cpp +++ b/gio-qt/source/dgiomount.cpp @@ -11,6 +11,9 @@ #include +// private +#include "dgiohelper.h" + using namespace Gio; class DGioMountPrivate @@ -150,71 +153,18 @@ QStringList DGioMount::themedIconNames() const { Q_D(const DGioMount); - QStringList iconNames; - Glib::RefPtr icon = d->getGmmMountInstance()->get_icon(); - Glib::RefPtr themedIcon = Glib::RefPtr::cast_dynamic(icon); -// if (G_IS_THEMED_ICON(themedIcon->gobj()) ) { -// qDebug() << "Yes and"; -// } - -// if (themedIcon) { -// qDebug() << "Yes"; -// } - - if (themedIcon) { - QStringList iconNames; - char **names; - char **iter; - names = NULL; - g_object_get(G_THEMED_ICON(themedIcon->gobj()), "names", &names, NULL); - for (iter = names; *iter; iter++) { - iconNames.append(QString(*iter)); - } - g_strfreev(names); - return iconNames; - } - -// return {QStringList::fromStdList(themedIcon->get_names())}; - -// char* name = 0; -// g_object_get(G_OBJECT(themedIcon->gobj()), "name", &name, NULL); -// return {QString(name)}; - -// if (themedIcon) { -// auto ustring_names = themedIcon->get_names(); -//// for (const Glib::ustring &str : ustring_names) { -//// iconNames.append(QString::fromStdString(str.raw())); -//// } -// } - - return iconNames; + return DGioPrivate::getThemedIconNames(icon); } QStringList DGioMount::themedSymbolicIconNames() const { Q_D(const DGioMount); - QStringList iconNames; - Glib::RefPtr icon = d->getGmmMountInstance()->get_symbolic_icon(); - Glib::RefPtr themedIcon = Glib::RefPtr::cast_dynamic(icon); - if (themedIcon) { - QStringList iconNames; - char **names; - char **iter; - names = NULL; - g_object_get(G_THEMED_ICON(themedIcon->gobj()), "names", &names, NULL); - for (iter = names; *iter; iter++) { - iconNames.append(QString(*iter)); - } - g_strfreev(names); - return iconNames; - } - - return iconNames; + return DGioPrivate::getThemedIconNames(icon); } void DGioMount::unmount(bool forceUnmount) diff --git a/gio-qt/dgiomountoperation.cpp b/gio-qt/source/dgiomountoperation.cpp similarity index 100% rename from gio-qt/dgiomountoperation.cpp rename to gio-qt/source/dgiomountoperation.cpp diff --git a/gio-qt/dgioutils.cpp b/gio-qt/source/dgioutils.cpp similarity index 100% rename from gio-qt/dgioutils.cpp rename to gio-qt/source/dgioutils.cpp diff --git a/gio-qt/dgiovolume.cpp b/gio-qt/source/dgiovolume.cpp similarity index 100% rename from gio-qt/dgiovolume.cpp rename to gio-qt/source/dgiovolume.cpp diff --git a/gio-qt/dgiovolumemanager.cpp b/gio-qt/source/dgiovolumemanager.cpp similarity index 100% rename from gio-qt/dgiovolumemanager.cpp rename to gio-qt/source/dgiovolumemanager.cpp