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

Dark mode theme #1047

Open
wants to merge 6 commits into
base: main
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
19 changes: 19 additions & 0 deletions .vscode/c_cpp_properties.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"configurations": [
{
"name": "Linux",
"includePath": [
"${workspaceFolder}/**",
"/usr/include/x86_64-linux-gnu/qt5/QtCore",
"/usr/include/x86_64-linux-gnu/qt5"
],
"defines": [],
"compilerPath": "/usr/bin/clang",
"cStandard": "c17",
"cppStandard": "c++14",
"intelliSenseMode": "linux-clang-x64"
},

],
"version": 4
}
3 changes: 3 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"C_Cpp.errorSquiggles": "disabled"
}
28 changes: 28 additions & 0 deletions .vscode/tasks.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
{
"tasks": [
{
"type": "cppbuild",
"label": "C/C++: g++ build active file",
"command": "/usr/bin/g++",
"args": [
"-fdiagnostics-color=always",
"-g",
"${file}",
"-o",
"${fileDirname}/${fileBasenameNoExtension}"
],
"options": {
"cwd": "${fileDirname}"
},
"problemMatcher": [
"$gcc"
],
"group": {
"kind": "build",
"isDefault": true
},
"detail": "Task generated by Debugger."
}
],
"version": "2.0.0"
}
40 changes: 40 additions & 0 deletions src/contentmanager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -922,3 +922,43 @@ void ContentManager::setSortBy(const QString& sortBy, const bool sortOrderAsc)
m_sortOrderAsc = sortOrderAsc;
emit(booksChanged());
}

void ContentManager::cancelBook(const QString& id, QModelIndex index)
{
auto text = gt("cancel-download-text");
text = text.replace("{{ZIM}}", QString::fromStdString(mp_library->getBookById(id).getTitle()));
showConfirmBox(gt("cancel-download"), text, mp_view, [=]() {
cancelBook(id);
emit managerModel->cancelDownload(index);
// Clear the download ID when cancelling the download
clearDownloadId(id);
});
}
//
void ContentManager::cancelBook(const QString& id)
{
if (!mp_downloader) {
return;
}
auto& b = mp_library->getBookById(id);
auto download = mp_downloader->getDownload(b.getDownloadId());
if (download->getStatus() != kiwix::Download::K_COMPLETE) {
download->cancelDownload();
}
QString dirPath = QString::fromStdString(kiwix::removeLastPathElement(download->getPath()));
QString filename = QString::fromStdString(kiwix::getLastPathElement(download->getPath())) + "*";
// incompleted downloaded file should be perma deleted
eraseBookFilesFromComputer(dirPath, filename, false);
// Clear the download ID when cancelling the download
clearDownloadId(id);
mp_library->removeBookFromLibraryById(id);
mp_library->save();
emit(oneBookChanged(id));
}
//
void ContentManager::clearDownloadId(const QString& id)
{
auto& b = mp_library->getBookById(id);
b.setDownloadId(""); // Clear the download ID
}
//
Empty file added src/downloader.cpp
Empty file.
43 changes: 43 additions & 0 deletions src/kiwixchoicebox.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,13 @@
#include <QDebug>
#include <QAbstractItemView>
#include <QScrollBar>
#include <QtWidgets>
#include "kiwixlineedit.h"
#include "kiwixlistwidget.h"

private :
Ui:: kiwixchoicebox * ui;

KiwixChoiceBox::KiwixChoiceBox(QWidget *parent) :
QWidget(parent),
ui(new Ui::kiwixchoicebox)
Expand Down Expand Up @@ -288,3 +292,42 @@
}
return selections;
}


class KiwixChoiceBox : public QWidget {
public:
KiwixChoiceBox(QWidget * parent = nullptr) : QWidget(parent) {
QVBoxLayout *layout = new QVBoxLayout(this);
QLabel * label = new QLabel("Choose your options:", this);
QPushButton * button = new QPushButton("Clear", this);
QCheckBox *darkmodecheckbox = new QCheckBox("Dark Mode", this);
layout -> ddWidget(label);
layout -> addWidget(button);
layout-> addWidget(darkmodecheckbox);

connect( darkmodecheckbox, &QCheckBox :: stateChanged, this, &KiwixChoiceBox:: toggleDarkMode);
}

public slots:
void toggleDarkMode(int state) {
if (state == Qt::Checked)
{
// here the code enables the dar mode
qApp->setStyleSheet("background-color: black; color: white;");
}

else
{

Check notice on line 321 in src/kiwixchoicebox.cpp

View check run for this annotation

codefactor.io / CodeFactor

src/kiwixchoicebox.cpp#L321

Redundant blank line at the start of a code block should be deleted. (whitespace/blank_line)
// the accordingly will disable the dark mode if the check box is not selected..
qApp->setStyleSheet("");
}
}
};

int main(int argc, char *argv[]) {
QApplication app(argc, argv);
KiwixChoiceBox box;
box.show();
return app.exec();
}
1 change: 1 addition & 0 deletions src/kiwixchoicebox.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#define KIWIXCHOICEBOX_H

#include <QWidget>
#include <QtWidgets>
#include <QCheckBox>
#include <QLineEdit>
#include <QListWidget>
Expand Down
9 changes: 9 additions & 0 deletions src/kiwixconfirmbox.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,3 +45,12 @@ void showInfoBox(QString title, QString text, QWidget *parent)
dialog->deleteLater();
});
}

void showInfoBox(QString title, QString text, QWidget *parent)
{
KiwixConfirmBox *dialog = new KiwixConfirmBox(title, text, true, parent);
QObject::connect(dialog, &KiwixConfirmBox::okClicked, [=]() {
dialog->deleteLater(); // Ensure the dialog is deleted after the OK button is clicked
});
dialog->show();
}
7 changes: 7 additions & 0 deletions ui/kiwixchoicebox.ui
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,13 @@
</property>
</widget>
</item>
<item>
<widget class="QCheckBox" name="darkModeCheckbox">
<property name="text">
<string>Dark Mode</string>
</property>
</widget>
</item>
</layout>
</widget>
</item>
Expand Down
10 changes: 10 additions & 0 deletions ui/kiwixconfirmbox.ui
Original file line number Diff line number Diff line change
Expand Up @@ -142,10 +142,20 @@
</property>
</widget>
</item>
<item> <!--added checkbox -->
<widget class="QCheckBox" name="darkModeCheckbox">
<property name="text">
<string>Dark Mode</string>
</property>
</widget>
</item>
</layout>
</item>
</layout>
</widget>
<resources/>
<connections/>
</ui>


<!-- added the check box part for the dark mode in the code -->
13 changes: 12 additions & 1 deletion ui/localkiwixserver.ui
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@
</size>
</property>
<property name="currentIndex">
<number>0</number>
<number>2</number>
</property>
<widget class="QWidget" name="StartServerOptions">
<layout class="QHBoxLayout" name="horizontalLayout_2">
Expand Down Expand Up @@ -182,6 +182,17 @@
</item>
</layout>
</widget>
<widget class="QWidget" name="DarkModeOptions">
<layout class="QHBoxLayout" name="horizontalLayout_4">
<item>
<widget class="QCheckBox" name="darkModeCheckbox">
<property name="text">
<string>Dark Mode</string>
</property>
</widget>
</item>
</layout>
</widget>
</widget>
</item>
<item row="1" column="0" colspan="3">
Expand Down
45 changes: 19 additions & 26 deletions ui/mainwindow.ui
Original file line number Diff line number Diff line change
Expand Up @@ -103,33 +103,26 @@
<bool>false</bool>
</attribute>
</widget>
<widget class="QMenuBar" name="menuBar">
<attribute name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>1024</width>
<height>25</height>
</rect>
</attribute>
</widget>
<widget class="QStatusBar" name="statusBar"/>
<widget class="QToolBar" name="toolBar">
<attribute name="toolBarArea">
<enum>TopToolBarArea</enum>
</attribute>
<attribute name="toolBarBreak">
<bool>false</bool>
</attribute>
</widget>
</widget>
<layoutdefault spacing="6" margin="11"/>
<customwidgets>
<customwidget>
<class>TopWidget</class>
<extends>QToolBar</extends>
<header>src/topwidget.h</header>
</customwidget>
<customwidget>
<class>TabBar</class>
<extends>QWidget</extends>
<header>src/tabbar.h</header>
<container>1</container>
</customwidget>
<customwidget>
<class>ContentManagerSide</class>
<extends>QWidget</extends>
<header>src/contentmanagerside.h</header>
<container>1</container>
</customwidget>
<customwidget>
<class>ReadingListBar</class>
<extends>QWidget</extends>
<header>src/readinglistbar.h</header>
<container>1</container>
</customwidget>
</customwidgets>
<resources/>
<connections/>
</ui>
Loading