Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WinUI --> QT #24

Merged
merged 8 commits into from
Aug 12, 2024
Merged
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
16 changes: 9 additions & 7 deletions .github/workflows/windows.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,19 @@ jobs:
with:
submodules: recursive
- name: "Setup Environment"
run: mkdir build
run: |
mkdir build
powershell -command "Invoke-WebRequest https://github.com/mlocati/gettext-iconv-windows/releases/download/v0.21-v1.16/gettext0.21-iconv1.16-shared-64.zip -OutFile gettext.zip"
powershell -command "Expand-Archive -Force 'gettext.zip'"
move gettext\bin\* C:\Windows\System32
choco install innosetup
- name: "Vcpkg"
uses: johnwason/vcpkg-action@v6
id: vcpkg
with:
pkgs: libnick libjpeg-turbo boost-gil
pkgs: libnick libjpeg-turbo boost-gil qtbase qtsvg qttools
triplet: x64-windows
revision: 02d93df47bb4c9b062921b26c77a251490127151
revision: e590c2b30c08caf1dd8d612ec602a003f9784b7d
token: ${{ secrets.GITHUB_TOKEN }}
github-binarycache: true
- name: "Build"
Expand All @@ -41,10 +46,7 @@ jobs:
- name: "Create Installer"
working-directory: ${{github.workspace}}/inno
run: |
choco install wget
choco install innosetup
wget https://aka.ms/vs/17/release/vc_redist.x64.exe -O vc_redist.x64.exe
wget https://aka.ms/windowsappsdk/1.5/1.5.240627000/windowsappruntimeinstall-x64.exe -O windowsappruntimeinstall-x64.exe
powershell -command "Invoke-WebRequest https://aka.ms/vs/17/release/vc_redist.x64.exe -OutFile vc_redist.x64.exe"
iscc setup.iss
- name: Upload
uses: actions/upload-artifact@v4
Expand Down
3 changes: 0 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,5 @@ _nickbuild/
CMakeUserPresets.json
compile_commands.json

# UI Files
*.ui

# Setup Files
inno/*.exe
4 changes: 2 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ if (POLICY CMP0141)
set(CMAKE_MSVC_DEBUG_INFORMATION_FORMAT "$<IF:$<AND:$<C_COMPILER_ID:MSVC>,$<CXX_COMPILER_ID:MSVC>>,$<$<CONFIG:Debug,RelWithDebInfo>:EditAndContinue>,$<$<CONFIG:Debug,RelWithDebInfo>:ProgramDatabase>>")
endif()

project("org.nickvision.spotlight" LANGUAGES C CXX VERSION 2024.6.1 DESCRIPTION "Find your favorite Windows spotlight images.")
project("org.nickvision.spotlight" LANGUAGES C CXX VERSION 2024.8.0 DESCRIPTION "Find your favorite Windows spotlight images.")
set(SHORT_NAME "spotlight")
include(GNUInstallDirs)

Expand All @@ -35,5 +35,5 @@ endif()

add_subdirectory("libspotlight")
if(WIN32)
add_subdirectory("org.nickvision.spotlight.winui")
add_subdirectory("org.nickvision.spotlight.qt")
endif()
15 changes: 7 additions & 8 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -105,15 +105,15 @@ Everyone is welcome to translate this app into their native or known languages,

##### Via Weblate

Spotlight is available to translate on [Weblate](https://hosted.weblate.org/engage/nickvision-application/)!
Spotlight is available to translate on [Weblate](https://hosted.weblate.org/engage/nickvision-spotlight/)!

##### Manually

To start translating the app, fork the repository and clone it locally.

Spotlight uses [gettext](https://www.gnu.org/software/gettext/manual/gettext.html#PO-Files) for translations. In the `resources/po` folder you will find files that can be edited in your favourite `*.po` files editor (or with any plain text editor).

If you want to create a new translation, copy the `application.pot` file and rename said copy as `<lang_code>.po`, where `<lang_code>` is the language code for your translation. Usually the code is two letters, but it can also be a specific locale code to differentiate between versions of the same language (for example, `pt` and `pt_BR`). **Also, add the language code to `LINGUAS` file** (keeping this file in alphabetical order).
If you want to create a new translation, copy the `spotlight.pot` file and rename said copy as `<lang_code>.po`, where `<lang_code>` is the language code for your translation. Usually the code is two letters, but it can also be a specific locale code to differentiate between versions of the same language (for example, `pt` and `pt_BR`). **Also, add the language code to `LINGUAS` file** (keeping this file in alphabetical order).

Edit your new translation file with correct translations for the English messages.

Expand All @@ -129,7 +129,7 @@ Spotlight is built using C++20 and platform-native user interface libraries. Wit

The project is split up into the following sub-projects:
- [libspotlight](#libspotlight)
- [org.nickvision.spotlight.winui](org.nickvision.spotlight.winui)
- [org.nickvision.spotlight.qt](org.nickvision.spotlight.qt)

The whole project utilizes the [MVC](https://en.wikipedia.org/wiki/Model%E2%80%93view%E2%80%93controller) pattern for separating data models and UI views.

Expand All @@ -140,15 +140,14 @@ This project contains all of the code used by all platforms of the app:
- `helpers` => Useful objects and functions specific to the application that can be used by all platforms.
- `models` => The data driven objects of the application (i.e. Configuration, Database, etc...).

##### org.nickvision.spotlight.winui
##### org.nickvision.spotlight.qt

This project contains all of the code used for the Windows platform (WinUI) version of the app, including installer scripts:
Powered by the [Windows App SDK](https://learn.microsoft.com/en-us/windows/apps/windows-app-sdk/)
This project contains all of the code used for the QT platform (Windows) version of the app:
- `controls` => Generic controls for the app.
- These UI objects are separate from views in that they should not be backed by a controller and should be easily ported to any other app.
- `helpers` => Useful objects and functions specific for the WinUI platform version of the app.
- `helpers` => Useful objects and functions specific for the QT platform version of the app.
- `resources` => Extra icons and other files specific for the QT platform version of the app.
- `views` => The views (pages, windows, dialogs, etc...) of the app.
- `installer` => Inno installer scripts.

#### Developing and Testing

Expand Down
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@ See [CONTRIBUTING.md](CONTRIBUTING.md) for details on how can you help the proje
<details>
<summary>WinUI</summary>

![Main](resources/screenshots/winui/main.png)
![Flip](resources/screenshots/winui/flip.png)
![Dark](resources/screenshots/winui/dark.png)
![Main](resources/screenshots/qt/main.png)
![Flip](resources/screenshots/qt/flip.png)
![Dark](resources/screenshots/qt/dark.png)
</details>

## Building Manually
Expand All @@ -38,7 +38,7 @@ A C++20 compiler is also required to build Spotlight.
1. Set the `VCPKG_ROOT` environment variable to the path of your vcpkg installation's root directory.
#### Windows
1. Set the `VCPKG_DEFAULT_TRIPLET` environment variable to `x64-windows`
1. Run `vcpkg install libnick libjpeg-turbo boost-gil`
1. Run `vcpkg install libnick libjpeg-turbo boost-gil qtbase qtsvg qttools`

### Building
1. First, clone/download the repo.
Expand Down
18 changes: 4 additions & 14 deletions inno/setup.iss
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@

#define MyAppName "Nickvision Spotlight"
#define MyAppShortName "Spotlight"
#define MyAppVersion "2024.7.0"
#define MyAppVersion "2024.8.0"
#define MyAppPublisher "Nickvision"
#define MyAppURL "https://nickvision.org"
#define MyAppExeName "org.nickvision.spotlight.winui.exe"
#define MyAppExeName "org.nickvision.spotlight.qt.exe"

[Setup]
; NOTE: The value of AppId uniquely identifies this application. Do not use the same AppId value in installers for other applications.
Expand Down Expand Up @@ -45,15 +45,6 @@ begin
MsgBox('Unable to install VC . Please try again', mbError, MB_OK);
end;

procedure SetupWinAppSDK();
var
ResultCode: Integer;
begin
if not Exec(ExpandConstant('{app}\deps\windowsappruntimeinstall-x64.exe'), '--quiet', '', SW_HIDE, ewWaitUntilTerminated, ResultCode)
then
MsgBox('Unable to install Windows App SDK. Please try again', mbError, MB_OK);
end;

procedure Cleanup();
begin
DelTree(ExpandConstant('{app}\deps'), True, True, True);
Expand All @@ -67,9 +58,8 @@ Name: "desktopicon"; Description: "{cm:CreateDesktopIcon}"; GroupDescription: "{

[Files]
Source: "vc_redist.x64.exe"; DestDir: "{app}\deps"; AfterInstall: SetupVC
Source: "windowsappruntimeinstall-x64.exe"; DestDir: "{app}\deps"; AfterInstall: SetupWinAppSDK
Source: "..\build\org.nickvision.spotlight.winui\Release\{#MyAppExeName}"; DestDir: "{app}"; Flags: ignoreversion
Source: "..\build\org.nickvision.spotlight.winui\Release\*"; DestDir: "{app}"; Flags: ignoreversion recursesubdirs createallsubdirs; AfterInstall: Cleanup
Source: "..\build\org.nickvision.spotlight.qt\Release\{#MyAppExeName}"; DestDir: "{app}"; Flags: ignoreversion
Source: "..\build\org.nickvision.spotlight.qt\Release\*"; DestDir: "{app}"; Flags: ignoreversion recursesubdirs createallsubdirs; AfterInstall: Cleanup
; NOTE: Don't use "Flags: ignoreversion" on any shared system files

[Icons]
Expand Down
4 changes: 2 additions & 2 deletions libspotlight/src/controllers/mainwindowcontroller.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,10 @@ namespace Nickvision::Spotlight::Shared::Controllers
m_logger{ UserDirectories::get(ApplicationUserDirectory::LocalData, m_appInfo.getName()) / "log.txt", Logging::LogLevel::Info, false },
m_spotlightManager{ m_appInfo.getName(), m_logger }
{
m_appInfo.setVersion({ "2024.7.0-next" });
m_appInfo.setVersion({ "2024.8.0-next" });
m_appInfo.setShortName(_("Spotlight"));
m_appInfo.setDescription(_("Find your favorite Windows spotlight images"));
m_appInfo.setChangelog("- Updated dependencies");
m_appInfo.setChangelog("- Redesigned the user interface with QT");
m_appInfo.setSourceRepo("https://github.com/NickvisionApps/Spotlight");
m_appInfo.setIssueTracker("https://github.com/NickvisionApps/Spotlight/issues/new");
m_appInfo.setSupportUrl("https://github.com/NickvisionApps/Spotlight/discussions");
Expand Down
69 changes: 69 additions & 0 deletions org.nickvision.spotlight.qt/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
set(OUTPUT_NAME "${PROJECT_NAME}.qt")
set(CMAKE_AUTOMOC ON)
set(CMAKE_AUTOUIC ON)
set(CMAKE_AUTORCC ON)
set(STARTUP_NOTIFY false)
add_definitions(-DQT_NO_KEYWORDS)

find_package(Qt6 REQUIRED COMPONENTS Core Gui Widgets Svg)
qt_standard_project_setup()

qt_add_executable(${OUTPUT_NAME}
"include/controls/aboutdialog.h"
"include/helpers/qthelpers.h"
"include/views/mainwindow.h"
"include/views/settingsdialog.h"
"include/application.h"
"src/controls/aboutdialog.ui"
"src/controls/aboutdialog.cpp"
"src/helpers/qthelpers.cpp"
"src/views/mainwindow.ui"
"src/views/mainwindow.cpp"
"src/views/settingsdialog.ui"
"src/views/settingsdialog.cpp"
"src/application.cpp"
"src/main.cpp"
"${OUTPUT_NAME}.qrc"
"${OUTPUT_NAME}.rc")
target_include_directories(${OUTPUT_NAME} PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}/include")
target_link_libraries(${OUTPUT_NAME} PRIVATE libspotlight Qt6::Core Qt6::Gui Qt6::Widgets Qt6::Svg)
if(WIN32)
set_target_properties(${OUTPUT_NAME} PROPERTIES WIN32_EXECUTABLE ON)
endif()

add_custom_target(qt_commands ALL DEPENDS "${CMAKE_CURRENT_BINARY_DIR}/__qt.h")
add_custom_command(OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/__qt.h" "${CMAKE_CURRENT_BINARY_DIR}/qt.h" COMMAND "${CMAKE_COMMAND}" -E touch "${CMAKE_CURRENT_BINARY_DIR}/qt.h")

if(WIN32)
add_custom_command(TARGET qt_commands POST_BUILD COMMAND Qt6::windeployqt ARGS $<TARGET_FILE:${OUTPUT_NAME}> --no-quick-import --no-translations --no-compiler-runtime)
endif()

if(HAS_GETTEXT)
foreach(LINGUA IN ITEMS ${LINGUAS})
if(MSVC)
add_custom_command(TARGET qt_commands PRE_BUILD COMMAND "${CMAKE_COMMAND}" -E make_directory "${CMAKE_CURRENT_BINARY_DIR}/$<CONFIG>/${LINGUA}/LC_MESSAGES")
add_custom_command(TARGET qt_commands PRE_BUILD COMMAND "${GETTEXT_MSGFMT_EXECUTABLE}" "${CMAKE_SOURCE_DIR}/resources/po/${LINGUA}.po" --output-file="${CMAKE_CURRENT_BINARY_DIR}/$<CONFIG>/${LINGUA}/LC_MESSAGES/${SHORT_NAME}.mo")
else()
add_custom_command(TARGET qt_commands PRE_BUILD COMMAND "${CMAKE_COMMAND}" -E make_directory "${CMAKE_CURRENT_BINARY_DIR}/${LINGUA}/LC_MESSAGES")
add_custom_command(TARGET qt_commands PRE_BUILD COMMAND "${GETTEXT_MSGFMT_EXECUTABLE}" "${CMAKE_SOURCE_DIR}/resources/po/${LINGUA}.po" --output-file="${CMAKE_CURRENT_BINARY_DIR}/${LINGUA}/LC_MESSAGES/${SHORT_NAME}.mo")
endif()
endforeach()
endif()

if(LINUX)
configure_file("${CMAKE_SOURCE_DIR}/resources/linux/${PROJECT_NAME}.desktop.in" "${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}.desktop" @ONLY)
configure_file("${CMAKE_SOURCE_DIR}/resources/linux/${PROJECT_NAME}.in" "${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}" @ONLY)
configure_file("${CMAKE_SOURCE_DIR}/resources/linux/${PROJECT_NAME}.metainfo.xml.in" "${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}.metainfo.xml" @ONLY)
install(DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/" DESTINATION "${CMAKE_INSTALL_LIBDIR}/${PROJECT_NAME}")
install(FILES "${CMAKE_CURRENT_BINARY_DIR}/${OUTPUT_NAME}" PERMISSIONS OWNER_READ OWNER_WRITE OWNER_EXECUTE GROUP_READ GROUP_EXECUTE WORLD_READ WORLD_EXECUTE DESTINATION "${CMAKE_INSTALL_LIBDIR}/${PROJECT_NAME}")
install(FILES "${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}" PERMISSIONS OWNER_READ OWNER_WRITE OWNER_EXECUTE GROUP_READ GROUP_EXECUTE WORLD_READ WORLD_EXECUTE DESTINATION "${CMAKE_INSTALL_BINDIR}")
install(FILES "${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}.desktop" DESTINATION "${CMAKE_INSTALL_DATADIR}/applications")
install(FILES "${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}.metainfo.xml" DESTINATION "${CMAKE_INSTALL_DATADIR}/metainfo")
install(FILES "${CMAKE_SOURCE_DIR}/resources/${PROJECT_NAME}.svg" "${CMAKE_SOURCE_DIR}/resources/${PROJECT_NAME}-devel.svg" DESTINATION "${CMAKE_INSTALL_DATADIR}/icons/hicolor/scalable/apps")
install(FILES "${CMAKE_SOURCE_DIR}/resources/${PROJECT_NAME}-symbolic.svg" DESTINATION "${CMAKE_INSTALL_DATADIR}/icons/hicolor/symbolic/apps")

find_program(UPDATE_DESKTOP_DATABASE_EXECUTABLE update-desktop-database)
if(UPDATE_DESKTOP_DATABASE_EXECUTABLE)
install(CODE "execute_process(COMMAND ${UPDATE_DESKTOP_DATABASE_EXECUTABLE})")
endif()
endif()
39 changes: 39 additions & 0 deletions org.nickvision.spotlight.qt/include/application.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
#ifndef APPLICATION_H
#define APPLICATION_H

#include <memory>
#include <QApplication>
#include "controllers/mainwindowcontroller.h"
#include "views/mainwindow.h"

namespace Nickvision::Spotlight::QT
{
/**
* @brief The main QT application point.
*/
class Application : public QApplication
{
Q_OBJECT

public:
/**
* @brief Constructs an Application.
* @param argc The number of arguments passed to the application
* @param argv The array of argument strings passed to the application
*/
Application(int argc, char* argv[]);
/**
* @brief Runs the application.
* @brief This runs the qt application loop.
* @return The return code from the qt application
*/
int exec();

private:
std::shared_ptr<Shared::Controllers::MainWindowController> m_controller;
std::shared_ptr<Views::MainWindow> m_mainWindow;
};
}


#endif //APPLICATION_H
37 changes: 37 additions & 0 deletions org.nickvision.spotlight.qt/include/controls/aboutdialog.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
#ifndef ABOUTDIALOG_H
#define ABOUTDIALOG_H

#include <string>
#include <QDialog>
#include <libnick/app/appinfo.h>

namespace Ui { class AboutDialog; }

namespace Nickvision::Spotlight::QT::Controls
{
/**
* @brief A dialog for displaying information about the application.
*/
class AboutDialog : public QDialog
{
Q_OBJECT

public:
/**
* @brief Constructs an AboutDialog.
* @param appInfo The AppInfo object for the application
* @param debugInfo The debug information for the application
* @param parent The parent widget
*/
AboutDialog(const App::AppInfo& appInfo, const std::string& debugInfo, QWidget* parent = nullptr);
/**
* @brief Destructs an AboutDialog.
*/
~AboutDialog();

private:
Ui::AboutDialog* m_ui;
};
}

#endif // ABOUTDIALOG_H
23 changes: 23 additions & 0 deletions org.nickvision.spotlight.qt/include/helpers/qthelpers.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#ifndef QTHELPERS_H
#define QTHELPERS_H

#include <functional>
#include <string>
#include <vector>
#include <QComboBox>

namespace Nickvision::Spotlight::QT::Helpers::QTHelpers
{
/**
* @brief Runs the function on the main UI thread.
* @param function The function to run
*/
void dispatchToMainThread(const std::function<void()>& function);
/**
* @brief Sets the items of a QComboBox from a vector of strings.
* @param comboBox The QComboBox to set the items of
*/
void setComboBoxItems(QComboBox* comboBox, const std::vector<std::string>& items);
}

#endif //QTHELPERS_H
Loading