Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
build system tweaks
	PLEASE NOTE BELOW however:
	https://twitter.com/malexaMK/status/1010658898376888321

desktop parser work
  • Loading branch information
Matthew Kehrer committed Jun 24, 2018
1 parent e02e7fa commit 8958f57
Show file tree
Hide file tree
Showing 10 changed files with 198 additions and 9 deletions.
7 changes: 7 additions & 0 deletions CMakeLists.txt
Expand Up @@ -45,6 +45,13 @@ ADD_CUSTOM_COMMAND(
COMMAND $(MAKE_COMMAND) clean && git clean -d -f
TARGET distclean
)
# Make target: `uninstall` FOR RM'ING STUFF INSTALLED TO PREFIX
ADD_CUSTOM_TARGET(uninstall @echo uninstall from PREFIX)
ADD_CUSTOM_COMMAND(
COMMENT "Removing files installed via make install"
COMMAND rm -rf "${CMAKE_INSTALL_PREFIX}/lib/x86_64-linux-gnu/libstacer-core.a" ; rm -rf "${CMAKE_INSTALL_PREFIX}/lib/libstacer-core.a" ; rm -rf "${CMAKE_INSTALL_PREFIX}/bin/stacer"
TARGET uninstall
)

# Subprojects
add_subdirectory(stacer-core)
Expand Down
4 changes: 4 additions & 0 deletions stacer-core/CMakeLists.txt
Expand Up @@ -20,5 +20,9 @@ target_link_libraries(${PROJECT_NAME} Qt5::Core Qt5::Network)
# add c++14
target_compile_options(${PROJECT_NAME} BEFORE PRIVATE --std=c++14)

if(STACERCORE_USING_GNU)
target_compile_options(${PROJECT_NAME} PRIVATE -fvisibility=hidden)
endif(STACERCORE_USING_GNU)

# make configure file
configure_file(stacer-core_config.h.cmake "${CMAKE_CURRENT_SOURCE_DIR}/stacer-core_config.h")
56 changes: 56 additions & 0 deletions stacer-core/Files/desktop_entry.cpp
@@ -0,0 +1,56 @@
#include "Files/desktop_entry.h"
#include <QFile>

DesktopEntry::DesktopEntry(QObject *parent)
: IDesktopApp(parent), p_entrycount(0), p_linecount(0)
{
p_fileobj = new QFile();
}

DesktopEntry::DesktopEntry(QObject *parent, const QString &folder, const QString &filename)
: IDesktopApp(parent), p_entrycount(0), p_linecount(0), p_parent_folder(folder), p_entry_filename(filename)
{
p_fileobj = new QFile();
}

DesktopEntry::~DesktopEntry()
{
if (p_fileobj != nullptr)
delete p_fileobj;
}

IDesktopApp::LPC_Pair DesktopEntry::get_line_param_count(void) const
{
return std::pair<int,int>(p_linecount, p_entrycount);
}

IDesktopApp::pNode_Vals DesktopEntry::get_nv_map(void) const
{
return const_cast<IDesktopApp::pNode_Vals>(&p_map_nv);
}

void DesktopEntry::create_nv_map(const IDesktopApp::LPC_Pair &l_e, void (*per_entry)(QString &, QString &, IDesktopApp::LPC_Pair &))
{
int line_count = l_e.first;
int entry_count = l_e.second;
const QByteArray zeroed(1024, '\0');
const QString rootnode(QString::fromWCharArray(IDesktopApp::get_root_node(), wcslen(IDesktopApp::get_root_node())));

for(auto p = IDesktopApp::LPC_Pair(line_count,entry_count); std::get<0>(p) > 0 && std::get<1>(p) > 0; p=std::make_pair(--line_count,--entry_count))
{
QByteArray qba = zeroed;
QString qsa = QString(qba);

if (qsa == rootnode)
continue;

per_entry(qsa.split(QChar('='))[0], qsa.split(QChar('='))[1], p);
}

}

void DesktopEntry::create_nv_map(const int lC, const int eC, void (*per_entry)(QString &, QString &, IDesktopApp::LPC_Pair &))
{
int line_count = lC;
int entry_count = eC;
}
34 changes: 34 additions & 0 deletions stacer-core/Files/desktop_entry.h
@@ -0,0 +1,34 @@
#ifndef _DESKTOP_ENTRY_H_
#define _DESKTOP_ENTRY_H_

#include <QMap>
#include <QFile>
#include "stacer-core_global.h"
#include "Iface/idesktopapp.h"

class STACERCORESHARED_EXPORT DesktopEntry : public IDesktopApp
{
Q_OBJECT

public:
explicit DesktopEntry(QObject *parent=nullptr);
DesktopEntry(QObject *parent, const QString& folder, const QString& filename);
~DesktopEntry() override;

virtual IDesktopApp::LPC_Pair get_line_param_count(void) const;
virtual IDesktopApp::pNode_Vals get_nv_map(void) const;

virtual void create_nv_map(const IDesktopApp::LPC_Pair &l_e, void(*per_entry)(QString&,QString&,IDesktopApp::LPC_Pair&));
virtual void create_nv_map(const int lC, const int eC, void(*per_entry)(QString&,QString&,IDesktopApp::LPC_Pair&));

private:
int p_linecount;
int p_entrycount;

IDesktopApp::Node_Vals p_map_nv;
QString p_parent_folder;
QString p_entry_filename;
QFile *p_fileobj;
};

#endif
14 changes: 14 additions & 0 deletions stacer-core/Iface/idesktopapp.cpp
@@ -0,0 +1,14 @@
#include "Iface/idesktopapp.h"

IDesktopApp::IDesktopApp( QObject* parent )
: QObject(parent)
{

}

IDesktopApp::~IDesktopApp()
{

}


38 changes: 38 additions & 0 deletions stacer-core/Iface/idesktopapp.h
@@ -0,0 +1,38 @@
#ifndef _IDESKTOPAPP_H_
#define _IDESKTOPAPP_H_

#include <QObject>
#include "stacer-core_global.h"

class STACERCORESHARED_EXPORT IDesktopApp : public QObject
{
Q_OBJECT
public:
typedef std::pair<int,int> LPC_Pair;
typedef QMap<QString,QString> Node_Vals;
typedef Node_Vals* pNode_Vals;
public:
explicit IDesktopApp( QObject* parent = nullptr );
~IDesktopApp() override;

Q_DECL_RELAXED_CONSTEXPR const wchar_t *get_root_node(void) {
return L"[DesktopEntry]";
}

// A - line count
// B - entry count
virtual IDesktopApp::LPC_Pair get_line_param_count(void) const = 0;
// ptr to qmap
virtual IDesktopApp::pNode_Vals get_nv_map(void) const = 0;

virtual void create_nv_map(const IDesktopApp::LPC_Pair &l_e, void(*per_entry)(QString&,QString&,IDesktopApp::LPC_Pair&)) = 0;
virtual void create_nv_map(const int lC, const int eC, void(*per_entry)(QString&,QString&,IDesktopApp::LPC_Pair&)) = 0;

virtual const QString getName(QString *key_override=nullptr) const = 0;

virtual const QString getExec(QString *key_override=nullptr) const = 0;
};

Q_DECLARE_METATYPE(::IDesktopApp*)

#endif
23 changes: 19 additions & 4 deletions stacer-core/Utils/file_util.cpp
Expand Up @@ -57,11 +57,26 @@ QStringList FileUtil::directoryList(const QString &path)
return list;
}

QStringList FileUtil::countFilesPerType(const QString &path, QString *opt_exten, long long *out_count)
QStringList FileUtil::directoryList(const QString &path, const bool include_dir)
{
QDir dir(path);
QStringList list;

if (!include_dir)
return FileUtil::directoryList(path);

for (const QFileInfo &info : dir.entryInfoList(QDir::NoDotAndDotDot | QDir::Files))
list << info.absoluteFilePath();

return list;
}


QStringList FileUtil::countFilesPerType(const QString &path, QString *opt_exten, long long *out_count, const bool include_dir)
{
long long count = 0;

QStringList unsorted_list = QStringList(FileUtil::directoryList(path));
QStringList unsorted_list = QStringList(FileUtil::directoryList(path,include_dir));
QStringList the_list;

for (const auto &str : unsorted_list)
Expand All @@ -80,7 +95,7 @@ QStringList FileUtil::countFilesPerType(const QString &path, QString *opt_exten,
return the_list;
}

QStringList FileUtil::getDesktopFiles(long long *out_totals)
QStringList FileUtil::getDesktopFiles(long long *out_totals, const bool include_dir)
{
QStringList desktop_file_paths = QStandardPaths::standardLocations(QStandardPaths::StandardLocation::ApplicationsLocation);
QStringList desktop_files;
Expand All @@ -90,7 +105,7 @@ QStringList FileUtil::getDesktopFiles(long long *out_totals)
for (const auto &str : desktop_file_paths)
{
long long j;
desktop_files << countFilesPerType(str, ddtop, &j);
desktop_files << countFilesPerType(str, ddtop, &j, include_dir);
total_desktop_files = total_desktop_files + j;
}

Expand Down
5 changes: 3 additions & 2 deletions stacer-core/Utils/file_util.h
Expand Up @@ -21,8 +21,9 @@ class STACERCORESHARED_EXPORT FileUtil

static bool writeFile(const QString &path, const QString &content, const QIODevice::OpenMode &mode = QIODevice::WriteOnly | QIODevice::Truncate);
static QStringList directoryList(const QString &path);
static QStringList countFilesPerType(const QString &path, QString *opt_exten, long long *out_count);
static QStringList getDesktopFiles(long long *out_totals = nullptr);
static QStringList directoryList(const QString &path, const bool include_dir);
static QStringList countFilesPerType(const QString &path, QString *opt_exten, long long *out_count, const bool include_dir=false);
static QStringList getDesktopFiles(long long *out_totals = nullptr, const bool include_dir=false);
static quint64 getFileSize(const QString &path);

private:
Expand Down
8 changes: 6 additions & 2 deletions stacer-core/stacer-core.pro
Expand Up @@ -40,8 +40,10 @@ SOURCES += \
Tools/package_tool.cpp \
Info/process_info.cpp \
Info/process.cpp \
Iface/idesktopapp.cpp \
Tools/apt_source_tool.cpp \
Tools/gnome_settings_tool.cpp
Tools/gnome_settings_tool.cpp \
Files/desktop_entry.cpp

HEADERS += \
stacer-core_global.h \
Expand All @@ -57,9 +59,11 @@ HEADERS += \
Tools/package_tool.h \
Info/process_info.h \
Info/process.h \
Iface/idesktopapp.h \
Tools/apt_source_tool.h \
Tools/gnome_settings_tool.h \
Tools/gnome_schema.h
Tools/gnome_schema.h \
Files/desktop_entry.h

unix {
target.path = /usr/lib
Expand Down
18 changes: 17 additions & 1 deletion stacer-core/stacer-core_global.h
Expand Up @@ -2,10 +2,26 @@
#define STACERCORE_GLOBAL_H

#include <QtCore/qglobal.h>
#include <QtCore/qobjectdefs.h>
#include <QtCore/qcompilerdetection.h>
#include "stacer-core_config.h"

#define TWO_EXPORT(a,b) a b

#if defined(STACERCORE_USING_GNU)
# ifndef __GNU__
# define __GNU__
# endif
# define STACERCORESHARED_NOEXPORT __attribute__((visibility ("hidden")))
# define STACERCORESHARED_EXPORT_GNU __attribute__((visibility ("default")))
#endif

#if defined(STACERCORE_LIBRARY)
# define STACERCORESHARED_EXPORT Q_DECL_EXPORT
# if defined(__GNU__)
# define STACERCORESHARED_EXPORT TWO_EXPORT(STACERCORESHARED_EXPORT_GNU,Q_DECL_EXPORT)
# else
# define STACERCORESHARED_EXPORT Q_DECL_EXPORT
# endif
#else
# define STACERCORESHARED_EXPORT Q_DECL_IMPORT
#endif
Expand Down

0 comments on commit 8958f57

Please sign in to comment.