Skip to content
This repository has been archived by the owner on Mar 13, 2018. It is now read-only.

[WIP] Code cleanup and switch to CMake #196

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 56 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
project(me.liriproject.Browser CXX)

cmake_minimum_required(VERSION 3.0.0 FATAL_ERROR)

OPTION(UPDATE_TRANSLATIONS "Update translations on compile" OFF)
OPTION(UBUNTU_TOUCH "Build for Ubuntu Touch" OFF)

# Find includes in corresponding build directories
set(CMAKE_INCLUDE_CURRENT_DIR ON)

# Instruct CMake to run moc and rrc automatically when needed
set(CMAKE_AUTOMOC ON)
set(CMAKE_AUTORCC ON)

# Extra CMake files
find_package(ECM 0.0.11 REQUIRED NO_MODULE)
set(CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake" ${ECM_MODULE_PATH} ${ECM_KDE_MODULE_DIR})

include(KDEInstallDirs)
include(KDECMakeSettings)
include(KDECompilerSettings)
include(FeatureSummary)

# Build flags
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fvisibility=hidden -fvisibility-inlines-hidden -Werror -Wall -Wextra -Wno-unused-parameter -pedantic -std=c++11")

# Disable debug output for release builds
if(CMAKE_BUILD_TYPE MATCHES "^[Rr]elease$")
add_definitions(-DQT_NO_DEBUG_OUTPUT)
endif()

# Minimum version requirements
set(QT_MIN_VERSION "5.4.0")

# Find Qt5
find_package(Qt5 ${QT_MIN_VERSION} CONFIG REQUIRED COMPONENTS
Core
Qml
Quick
Widgets
Xml
Svg
Multimedia
Network
WebEngine
WebEngineWidgets
LinguistTools)

add_subdirectory(data)
add_subdirectory(plugins)
add_subdirectory(src)

# Display feature summary
feature_summary(WHAT ALL FATAL_ON_MISSING_REQUIRED_PACKAGES)
MESSAGE(STATUS "UPDATE TRANSLATIONS: ${UPDATE_TRANSLATIONS}")
MESSAGE(STATUS "BUILD FOR UBUNTU TOUCH: ${UBUNTU_TOUCH}")
11 changes: 11 additions & 0 deletions data/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
if(UNIX)
# Install the desktop and appdata files
install(FILES ${PROJECT_NAME}.desktop
DESTINATION ${CMAKE_INSTALL_DATADIR}/applications)
install(FILES ${PROJECT_NAME}.appdata.xml
DESTINATION ${CMAKE_INSTALL_METAINFODIR})

# Install the icon
install(FILES icons/liri-browser.png
DESTINATION ${CMAKE_INSTALL_DATADIR}/icons/hicolor/512x512/apps)
endif()
File renamed without changes.
File renamed without changes.
File renamed without changes
1 change: 0 additions & 1 deletion config/liri-config.json → data/liri-config.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,5 @@
"bookmarks": true
}
}

}
}
Empty file.
Empty file.
10 changes: 10 additions & 0 deletions plugins/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
set(PLUGINS
omniplet-bookmarks
omniplet-calculator
omniplet-duckduckgo
omniplet-history
omniplet-weather
)

install(DIRECTORY ${PLUGINS}
DESTINATION ${CMAKE_INSTALL_DATADIR}/liri-browser/plugins)
27 changes: 27 additions & 0 deletions scripts/qrc.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#! /usr/bin/env python3

# Generate a Qt Resource file from the contents of a list of directories
# qrc.py <dir1> <dir2> ...

import os, os.path
import sys

file_list = []

for directory in sys.argv[1:]:
sub_list = []

for root, dirs, files in os.walk(directory):
sub_list += [os.path.join(root, filename) for filename in files]

sub_list.sort()
file_list += sub_list

contents = '<!DOCTYPE RCC>\n<RCC version="1.0">\n <qresource>\n'

for filename in file_list:
contents += ' <file>' + filename + '</file>\n'

contents += ' </qresource>\n</RCC>\n'

print(contents)
50 changes: 50 additions & 0 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
set(SOURCES
config.cpp clipboardadapter.cpp
cursor/cursor.cpp
plugins/pluginsengine.cpp plugins/plugin.cpp plugins/api.cpp plugins/urlopener.cpp
liri-browser.qrc
)

# Platform-specific stuff

if(UBUNTU_TOUCH)
set(SOURCES ${SOURCES} ubuntu/main.cpp)
else()
set(SOURCES ${SOURCES} main.cpp)
endif()

if(APPLE)
set(MACOSX_BUNDLE_ICON_FILE liri-browser.icns)
set_source_files_properties(${CMAKE_SOURCE_DIR}/data/icons/liri-browser.icns
PROPERTIES MACOSX_PACKAGE_LOCATION Resources)
set(SOURCES ${SOURCES} ${CMAKE_SOURCE_DIR}/data/icons/liri-browser.icns)
ENDIF(APPLE)

# Translations

file(GLOB_RECURSE TS_SOURCES *.cpp *.h *.qml *.js ${CMAKE_SOURCE_DIR}/plugins/*.ts)
file(GLOB TS_FILES "${CMAKE_SOURCE_DIR}/translations/*.ts")

if(UPDATE_TRANSLATIONS)
qt5_create_translation(QM_FILES ${TS_SOURCES} ${TS_FILES})
else()
qt5_add_translation(QM_FILES ${TS_FILES})
endif(UPDATE_TRANSLATIONS)

# Create and install the executable

add_executable(liri-browser ${SOURCES} ${QM_FILES})
target_link_libraries(liri-browser
Qt5::Core
Qt5::Qml
Qt5::Quick
Qt5::Widgets
Qt5::Xml
Qt5::Svg
Qt5::Multimedia
Qt5::Network
Qt5::WebEngine
Qt5::WebEngineWidgets)

install(TARGETS liri-browser
DESTINATION ${CMAKE_INSTALL_BINDIR})
52 changes: 33 additions & 19 deletions src/config.cpp
Original file line number Diff line number Diff line change
@@ -1,46 +1,60 @@
#include "config.h"

#include <QDebug>
#include <QFile>
#include <QByteArray>
#include <QJsonDocument>
#include <QJsonObject>
#include <QVariant>
#include "config.h"

Config::Config(QObject *parent) : QObject(parent){
#include <QStandardPaths>

Config::Config(QObject *parent) : QObject(parent)
{
// Nothing needed here
}

bool Config::load()
{
QStringList configPaths = QStandardPaths::locateAll(QStandardPaths::ConfigLocation,
QStringLiteral("liri-config.json"));

bool Config::load(){
QFile configFile("config/liri-config.json");

if (!configFile.open(QIODevice::ReadOnly)) {
qWarning("Couldn't open config file.");
if (configPaths.isEmpty()) {
qWarning() << "Configuration not found!";
return false;
}

QByteArray jsonData = configFile.readAll();
QJsonDocument configDoc (QJsonDocument::fromJson(jsonData));
foreach (QString path, configPaths) {
QFile configFile(path);

auto json = configDoc.object();
QJsonObject pluginsObject = json["plugins"].toObject();
this->plugins = pluginsObject.toVariantMap();
if (!configFile.open(QIODevice::ReadOnly)) {
qWarning() << "Couldn't open config file:" << path;
}

return true;
}
QByteArray jsonData = configFile.readAll();
QJsonDocument configDoc(QJsonDocument::fromJson(jsonData));

auto json = configDoc.object();
QJsonObject pluginsObject = json["plugins"].toObject();
this->plugins = pluginsObject.toVariantMap();

return true;
}

bool Config::save(){
return false;
}

bool Config::save()
{
return false;
}

QVariantMap Config::getPluginPermissions(QString pluginName) {
QVariantMap Config::getPluginPermissions(QString pluginName)
{
return this->plugins[pluginName].toMap()["permissions"].toMap();
}


bool Config::getPluginIsPermitted(QString pluginName, QString feature){
bool Config::getPluginIsPermitted(QString pluginName, QString feature)
{
QVariantMap permissions = this->getPluginPermissions(pluginName);
if (permissions.keys().contains(feature))
return permissions[feature].toBool();
Expand Down
21 changes: 11 additions & 10 deletions src/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,20 @@
#include <QObject>
#include <QVariantMap>

class Config : public QObject{
Q_OBJECT
public:
bool load();
bool save();
class Config : public QObject
{
Q_OBJECT
public:
bool load();
bool save();

QVariantMap getPluginPermissions(QString pluginName);
bool getPluginIsPermitted(QString pluginName, QString feature);
QVariantMap getPluginPermissions(QString pluginName);
bool getPluginIsPermitted(QString pluginName, QString feature);

explicit Config(QObject *parent = 0);
private:
QVariantMap plugins;
explicit Config(QObject *parent = 0);

private:
QVariantMap plugins;
};

#endif // CONFIG_H
68 changes: 68 additions & 0 deletions src/liri-browser.qrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
<!DOCTYPE RCC>
<RCC version="1.0">
<qresource>
<file>qml/BaseApplication.qml</file>
<file>qml/BrowserWindow2.qml</file>
<file>qml/DesktopApplication.qml</file>
<file>qml/ResizeArea.qml</file>
<file>qml/components/LoadingIndicator.qml</file>
<file>qml/components/MenuFieldThemed.qml</file>
<file>qml/components/QuickSearches.qml</file>
<file>qml/components/QuickSearchesList.qml</file>
<file>qml/components/ScrollbarThemed.qml</file>
<file>qml/components/ShadowOverlay.qml</file>
<file>qml/components/TextFieldThemed.qml</file>
<file>qml/js/utils.js</file>
<file>qml/model/BookmarksModel.qml</file>
<file>qml/model/DashboardModel.qml</file>
<file>qml/model/DownloadsModel.qml</file>
<file>qml/model/HistoryModel.qml</file>
<file>qml/model/SearchSuggestionsModel.qml</file>
<file>qml/model/Tab.qml</file>
<file>qml/model/TabsModel.qml</file>
<file>qml/popups/BookmarksDrawer.qml</file>
<file>qml/popups/ColorChooser.qml</file>
<file>qml/popups/ColorPicker.qml</file>
<file>qml/popups/DownloadsDrawer.qml</file>
<file>qml/popups/HistoryDrawer.qml</file>
<file>qml/popups/RightDrawer.qml</file>
<file>qml/ubuntu/BrowserOxideWebView.qml</file>
<file>qml/ubuntu/Main.qml</file>
<file>qml/ubuntu/Settings.qml</file>
<file>qml/ubuntu/UbuntuApplication.qml</file>
<file>qml/ubuntu/UbuntuOmniboxOverlay.qml</file>
<file>qml/ubuntu/oxide-user.js</file>
<file>qml/ui/BookmarkItem.qml</file>
<file>qml/ui/BookmarksBar.qml</file>
<file>qml/ui/BrowserPage.qml</file>
<file>qml/ui/BrowserTabBar.qml</file>
<file>qml/ui/BrowserToolbar.qml</file>
<file>qml/ui/BrowserWindow.qml</file>
<file>qml/ui/FullscreenBar.qml</file>
<file>qml/ui/MaterialWindow.qml</file>
<file>qml/ui/Omnibox.qml</file>
<file>qml/ui/SearchSuggestions.qml</file>
<file>qml/ui/ShortcutActions.qml</file>
<file>qml/ui/SystemBar.qml</file>
<file>qml/ui/SystemButtons.qml</file>
<file>qml/ui/TabBarItem.qml</file>
<file>qml/ui/TabBarItemDelegate.qml</file>
<file>qml/ui/TabsList.qml</file>
<file>qml/ui/TabsListPage.qml</file>
<file>qml/views/BaseBrowserView.qml</file>
<file>qml/views/BrowserView.qml</file>
<file>qml/views/browser/BrowserWebView.qml</file>
<file>qml/views/dashboard/DashboardView.qml</file>
<file>qml/views/media/PlayerPage.qml</file>
<file>qml/views/settings/QuickSearchesPage.qml</file>
<file>qml/views/settings/QuickSearchesView.qml</file>
<file>qml/views/settings/SettingsDrawer.qml</file>
<file>qml/views/settings/SettingsPage.qml</file>
<file>qml/views/settings/SettingsView.qml</file>
<file>qml/views/settings/SitesColors.qml</file>
<file>qml/views/settings/SitesColorsList.qml</file>
<file>qml/views/settings/SitesColorsPage.qml</file>
<file>qml/views/settings/SitesColorsView.qml</file>
</qresource>
</RCC>

Loading