Skip to content

Commit

Permalink
Check whether executable is ELF or has shebang; clean up
Browse files Browse the repository at this point in the history
  • Loading branch information
probonopd committed Aug 10, 2023
1 parent c5dbb49 commit 2bac8c9
Show file tree
Hide file tree
Showing 21 changed files with 452 additions and 122 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -54,3 +54,4 @@ compile_commands.json
build/*

.idea
.vscode
61 changes: 38 additions & 23 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@

cmake_minimum_required(VERSION 3.5)

# Add the tests subdirectory
add_subdirectory(tests)

# Do not print deprecated warnings for Qt5 or KF5
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-deprecated-declarations")

Expand Down Expand Up @@ -36,53 +39,65 @@ set(CMAKE_INSTALL_RPATH $ORIGIN/../lib)
# 'launch' binary in different paths
add_executable(launch
src/launch.cpp
src/dbmanager.h
src/dbmanager.cpp
src/applicationinfo.h
src/applicationinfo.cpp
src/appdiscovery.h
src/appdiscovery.cpp
src/DbManager.h
src/DbManager.cpp
src/ApplicationInfo.h
src/ApplicationInfo.cpp
src/AppDiscovery.h
src/AppDiscovery.cpp
src/extattrs.h
src/extattrs.cpp
src/launcher.h
src/launcher.cpp
src/applicationselectiondialog.h src/applicationselectiondialog.cpp src/applicationselectiondialog.ui
src/ApplicationSelectionDialog.h
src/ApplicationSelectionDialog.cpp
src/ApplicationSelectionDialog.ui
src/Executable.cpp
src/Executable.h
)

add_executable(open
src/launch.cpp
src/dbmanager.h
src/dbmanager.cpp
src/applicationinfo.h
src/applicationinfo.cpp
src/appdiscovery.h
src/appdiscovery.cpp
src/DbManager.h
src/DbManager.cpp
src/ApplicationInfo.h
src/ApplicationInfo.cpp
src/AppDiscovery.h
src/AppDiscovery.cpp
src/extattrs.h
src/extattrs.cpp
src/launcher.h
src/launcher.cpp
src/applicationselectiondialog.h src/applicationselectiondialog.cpp src/applicationselectiondialog.ui
src/ApplicationSelectionDialog.h
src/ApplicationSelectionDialog.cpp
src/ApplicationSelectionDialog.ui
src/Executable.cpp
src/Executable.h
)

add_executable(xdg-open
src/launch.cpp
src/dbmanager.h
src/dbmanager.cpp
src/applicationinfo.h
src/applicationinfo.cpp
src/appdiscovery.h
src/appdiscovery.cpp
src/DbManager.h
src/DbManager.cpp
src/ApplicationInfo.h
src/ApplicationInfo.cpp
src/AppDiscovery.h
src/AppDiscovery.cpp
src/extattrs.h
src/extattrs.cpp
src/launcher.h
src/launcher.cpp
src/applicationselectiondialog.h src/applicationselectiondialog.cpp src/applicationselectiondialog.ui
src/ApplicationSelectionDialog.h
src/ApplicationSelectionDialog.cpp
src/ApplicationSelectionDialog.ui
src/Executable.cpp
src/Executable.h
)

add_executable(bundle-thumbnailer
src/bundle-thumbnailer.cpp
src/dbmanager.h
src/dbmanager.cpp
src/DbManager.h
src/DbManager.cpp
src/extattrs.h
src/extattrs.cpp
)
Expand Down
4 changes: 2 additions & 2 deletions src/appdiscovery.cpp → src/AppDiscovery.cpp
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
#include "appdiscovery.h"
#include "AppDiscovery.h"

#include <QDebug>
#include <QDir>
#include <QStandardPaths>
#include <QStringList>

#include "dbmanager.h"
#include "DbManager.h"

AppDiscovery::AppDiscovery(DbManager *db)
{
Expand Down
52 changes: 52 additions & 0 deletions src/AppDiscovery.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
#ifndef APPDISCOVERY_H
#define APPDISCOVERY_H

#include <QStringList>

#include "DbManager.h"

/**
* @file AppDiscovery.h
* @class AppDiscovery
* @brief A class for discovering and handling application locations.
*
* This class is responsible for discovering well-known application locations and
* finding applications within those locations.
*/
class AppDiscovery
{
public:
/**
* Constructor.
*
* @param db A pointer to the DbManager instance for database handling.
*/
AppDiscovery(DbManager *db);

/**
* Destructor.
*/
~AppDiscovery();

/**
* Retrieve a list of well-known application locations.
*
* @return A QStringList containing well-known application locations.
*/
QStringList wellKnownApplicationLocations();

/**
* Find and process applications within specified locations.
*
* This function searches for applications within the provided locations and
* handles each discovered application using the associated DbManager instance.
*
* @param locationsContainingApps A list of locations to search for applications.
*/
void findAppsInside(QStringList locationsContainingApps);

private:
DbManager *dbman; /**< A pointer to the DbManager instance. */
};

#endif // APPDISCOVERY_H
43 changes: 19 additions & 24 deletions src/applicationinfo.cpp → src/ApplicationInfo.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#include "applicationinfo.h"
#include "ApplicationInfo.h"
#include <KWindowInfo>
#include <QDebug>
#include <QStringList>
Expand Down Expand Up @@ -26,41 +26,36 @@ ApplicationInfo::~ApplicationInfo() { }

// Returns the name of the most nested bundle a file is in,
// or an empty string if the file is not in a bundle
QString ApplicationInfo::bundlePath(QString path)
QString ApplicationInfo::bundlePath(const QString &path)
{
QDir(path).cleanPath(path);
QString ourPath = path;
QDir(path).cleanPath(ourPath);
// Remove trailing slashes
while (path.endsWith("/")) {
path.remove(path.length() - 1, 1);
while (ourPath.endsWith("/")) {
ourPath.remove(path.length() - 1, 1);
}
if (path.endsWith(".app")) {
return path;
} else if (path.contains(".app/")) {
QStringList parts = path.split(".app");
if (ourPath.endsWith(".app")) {
return ourPath;
} else if (ourPath.contains(".app/")) {
QStringList parts = ourPath.split(".app");
parts.removeLast();
return parts.join(".app");
} else if (path.endsWith(".AppDir")) {
return path;
} else if (path.contains(".AppDir/")) {
QStringList parts = path.split(".AppDir");
} else if (ourPath.endsWith(".AppDir")) {
return ourPath;
} else if (ourPath.contains(".AppDir/")) {
QStringList parts = ourPath.split(".AppDir");
parts.removeLast();
return parts.join(".AppDir");
} else if (path.endsWith(".AppImage")) {
return path;
} else if (path.endsWith(".desktop")) {
return path;
} else if (ourPath.endsWith(".AppImage")) {
return ourPath;
} else if (ourPath.endsWith(".desktop")) {
return ourPath;
} else {
return "";
}
}

// Returns the name of the bundle
QString ApplicationInfo::bundleName(unsigned long long id)
{
return "";
}

QString ApplicationInfo::applicationNiceNameForPath(QString path)
QString ApplicationInfo::applicationNiceNameForPath(const QString &path)
{
QString applicationNiceName;
QString bp = bundlePath(path);
Expand Down
94 changes: 94 additions & 0 deletions src/ApplicationInfo.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
#ifndef APPLICATIONINFO_H
#define APPLICATIONINFO_H

#include <QString>

/*
* https://en.wikipedia.org/wiki/Rule_of_three_(computer_programming)
* Currently being used in:
* Menu (master)
* launch (copy)
*/

class ApplicationInfo
{
public:
/**
* Constructor.
*
* Creates an instance of the ApplicationInfo class.
*/
explicit ApplicationInfo();

/**
* Destructor.
*
* Cleans up resources associated with the ApplicationInfo instance.
*/
~ApplicationInfo();

/**
* Get the most nested bundle path of a file.
*
* This function returns the name of the most nested bundle a file is in,
* or an empty string if the file is not in a bundle.
*
* @param path The path of the file to check.
* @return The bundle path or an empty string.
*/
static QString bundlePath(const QString &path);

/**
* Get a human-readable application name for a given path.
*
* This function returns a nice name for the application based on its path.
*
* @param path The path of the application.
* @return The application nice name.
*/
static QString applicationNiceNameForPath(const QString &path);

/**
* Get the bundle path for a given process ID.
*
* This function returns the bundle path for a process ID, based on the
* LAUNCHED_BUNDLE environment variable set by the 'launch' command.
*
* @param pid The process ID.
* @return The bundle path.
*/
static QString bundlePathForPId(unsigned int pid);

/**
* Get the bundle path for a given window ID.
*
* This function returns the bundle path associated with a window ID.
*
* @param id The window ID.
* @return The bundle path.
*/
static QString bundlePathForWId(unsigned long long id);

/**
* Get the path for a given window ID.
*
* This function returns the path associated with a window ID.
*
* @param id The window ID.
* @return The path.
*/
static QString pathForWId(unsigned long long id);

/**
* Get a human-readable application name for a given window ID.
*
* This function returns a nice name for the application associated with
* a window ID.
*
* @param id The window ID.
* @return The application nice name.
*/
static QString applicationNiceNameForWId(unsigned long long id);
};

#endif // APPLICATIONINFO_H
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
#include "applicationselectiondialog.h"
#include "ui_applicationselectiondialog.h"
#include "ApplicationSelectionDialog.h"
#include "ui_ApplicationSelectionDialog.h"
#include <QDebug>

#include "extattrs.h"
#include <QDir>
#include <QMessageBox>
#include <QPushButton>
#include "launcher.h"
#include "dbmanager.h"
#include "DbManager.h"
#include <QFileDialog>


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

#include <QDialog>
#include <QListWidget>
#include "dbmanager.h"
#include "DbManager.h"

namespace Ui {
class ApplicationSelectionDialog;
Expand Down
File renamed without changes.
2 changes: 1 addition & 1 deletion src/dbmanager.cpp → src/DbManager.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#include "dbmanager.h"
#include "DbManager.h"
#include <QDebug>
#include <QDir>
#include <QDirIterator>
Expand Down
File renamed without changes.
Loading

0 comments on commit 2bac8c9

Please sign in to comment.