mirror of
https://github.com/altlinux/admc.git
synced 2024-10-26 08:55:21 +03:00
Theme selection dialog is refactored
ChooseThemeDialog is merged with SelectThemeImpl class and refactored. SelectThemeImpl class is removed.
This commit is contained in:
parent
81abd8e80b
commit
ac2eef8416
@ -184,7 +184,6 @@ set(ADMC_SOURCES
|
||||
console_impls/all_policies_folder_impl.cpp
|
||||
console_impls/policy_ou_impl.cpp
|
||||
console_impls/found_policy_impl.cpp
|
||||
console_impls/select_theme_impl.cpp
|
||||
|
||||
admc.qrc
|
||||
admc-icons.qrc
|
||||
|
@ -1,23 +1,23 @@
|
||||
#include "choose_theme_dialog.h"
|
||||
#include "ui_choose_theme_dialog.h"
|
||||
#include "console_impls/select_theme_impl.h"
|
||||
#include <settings.h>
|
||||
#include <QFile>
|
||||
#include <QDirIterator>
|
||||
|
||||
ChooseThemeDialog::ChooseThemeDialog(QWidget * parent):
|
||||
|
||||
ChooseThemeDialog::ChooseThemeDialog(QWidget *parent):
|
||||
QDialog(parent)
|
||||
{
|
||||
ui = new Ui::ChooseThemeDialog();
|
||||
ui->setupUi(this);
|
||||
|
||||
setAttribute(Qt::WA_DeleteOnClose);
|
||||
|
||||
setup_theme_list();
|
||||
|
||||
connect(ui->button_box, &QDialogButtonBox::accepted, this, &ChooseThemeDialog::accepted);
|
||||
}
|
||||
|
||||
void ChooseThemeDialog::setup_theme_list()
|
||||
{
|
||||
auto themes = SelectThemeImpl().get_available_theme_list();
|
||||
auto themes = get_available_theme_list();
|
||||
|
||||
theme_model = new QStringListModel(this);
|
||||
|
||||
@ -26,7 +26,60 @@ void ChooseThemeDialog::setup_theme_list()
|
||||
ui->theme_list->setModel(theme_model);
|
||||
}
|
||||
|
||||
void ChooseThemeDialog::accepted()
|
||||
void ChooseThemeDialog::accept()
|
||||
{
|
||||
SelectThemeImpl().apply_theme(ui->theme_list->currentIndex().data().toString());
|
||||
apply_theme(ui->theme_list->currentIndex().data().toString());
|
||||
QDialog::accept();
|
||||
}
|
||||
|
||||
void ChooseThemeDialog::apply_theme(QString theme_name)
|
||||
{
|
||||
QIcon::setThemeName(theme_name);
|
||||
settings_set_variant(SETTING_app_active_theme, theme_name);
|
||||
}
|
||||
|
||||
QStringList ChooseThemeDialog::get_themes_from_dir(QString path_to_dir)
|
||||
{
|
||||
QDirIterator it(path_to_dir, QStringList(theme_file_name), QDir::Files | QDir::NoDotAndDotDot | QDir::NoSymLinks, QDirIterator::Subdirectories);
|
||||
|
||||
QStringList files;
|
||||
|
||||
while(it.hasNext())
|
||||
{
|
||||
files << it.next();
|
||||
}
|
||||
|
||||
return parse_theme_names(files);
|
||||
}
|
||||
|
||||
QStringList ChooseThemeDialog::parse_theme_names(const QStringList & theme_path_list)
|
||||
{
|
||||
QRegularExpression regex(this->theme_name_regex_pattern);
|
||||
|
||||
QStringList result;
|
||||
|
||||
for (int i = 0; i < theme_path_list.size(); ++i)
|
||||
{
|
||||
QFile theme_file(theme_path_list.at(i));
|
||||
|
||||
if(!theme_file.open(QIODevice::ReadOnly | QIODevice::Text))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
auto matched_data = regex.match(theme_file.readAll(), 0, QRegularExpression::PartialPreferCompleteMatch).captured();
|
||||
|
||||
result << matched_data.mid(theme_name_regex_pattern.length() - 2);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
QStringList ChooseThemeDialog::get_available_theme_list()
|
||||
{
|
||||
auto available_theme_paths = get_themes_from_dir(this->system_icons_dir_path);
|
||||
available_theme_paths.append(get_themes_from_dir(this->user_icons_dir_path));
|
||||
available_theme_paths.append(get_themes_from_dir(this->app_theme_path));
|
||||
|
||||
return available_theme_paths;
|
||||
}
|
||||
|
@ -3,6 +3,7 @@
|
||||
|
||||
#include <QDialog>
|
||||
#include <QStringListModel>
|
||||
#include <QDebug>
|
||||
namespace Ui {
|
||||
class ChooseThemeDialog;
|
||||
}
|
||||
@ -10,17 +11,28 @@ namespace Ui {
|
||||
class ChooseThemeDialog : public QDialog
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
ChooseThemeDialog(QWidget * parent);
|
||||
Ui::ChooseThemeDialog *ui;
|
||||
void setup_theme_list();
|
||||
void apply_theme();
|
||||
|
||||
private slots:
|
||||
void accepted();
|
||||
void accept() override;
|
||||
|
||||
private:
|
||||
QStringListModel * theme_model;
|
||||
const QString app_theme_path = ":/icons";
|
||||
const QString system_icons_dir_path = "/usr/share/icons";
|
||||
QString user_icons_dir_path;
|
||||
|
||||
const QString theme_name_regex_pattern = "Name=.*";
|
||||
const QString theme_file_name = "index.theme";
|
||||
|
||||
void setup_theme_list();
|
||||
void apply_theme(QString theme_name);
|
||||
QStringList get_available_theme_list();
|
||||
QStringList parse_theme_names(const QStringList & theme_path_list);
|
||||
QStringList get_themes_from_dir(QString path_to_dir);
|
||||
};
|
||||
|
||||
#endif // CHOOSETHEMEDIALOG_H
|
||||
|
@ -6,70 +6,47 @@
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>337</width>
|
||||
<height>289</height>
|
||||
<width>293</width>
|
||||
<height>260</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="windowTitle">
|
||||
<string>ChooseTheme</string>
|
||||
<string>Theme selection</string>
|
||||
</property>
|
||||
<widget class="QDialogButtonBox" name="button_box">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>80</x>
|
||||
<y>250</y>
|
||||
<width>171</width>
|
||||
<height>32</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
</property>
|
||||
<property name="standardButtons">
|
||||
<set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
|
||||
</property>
|
||||
</widget>
|
||||
<widget class="QListView" name="theme_list">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>40</x>
|
||||
<y>50</y>
|
||||
<width>256</width>
|
||||
<height>192</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="editTriggers">
|
||||
<set>QAbstractItemView::NoEditTriggers</set>
|
||||
</property>
|
||||
<property name="showDropIndicator" stdset="0">
|
||||
<bool>false</bool>
|
||||
</property>
|
||||
<property name="defaultDropAction">
|
||||
<enum>Qt::IgnoreAction</enum>
|
||||
</property>
|
||||
<property name="selectionMode">
|
||||
<enum>QAbstractItemView::SingleSelection</enum>
|
||||
</property>
|
||||
<property name="resizeMode">
|
||||
<enum>QListView::Adjust</enum>
|
||||
</property>
|
||||
<property name="wordWrap">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
</widget>
|
||||
<widget class="QLabel" name="label">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>50</x>
|
||||
<y>20</y>
|
||||
<width>231</width>
|
||||
<height>20</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Choose application theme from list above</string>
|
||||
</property>
|
||||
</widget>
|
||||
<layout class="QVBoxLayout" name="verticalLayout">
|
||||
<item>
|
||||
<widget class="QListView" name="theme_list">
|
||||
<property name="editTriggers">
|
||||
<set>QAbstractItemView::NoEditTriggers</set>
|
||||
</property>
|
||||
<property name="showDropIndicator" stdset="0">
|
||||
<bool>false</bool>
|
||||
</property>
|
||||
<property name="defaultDropAction">
|
||||
<enum>Qt::IgnoreAction</enum>
|
||||
</property>
|
||||
<property name="selectionMode">
|
||||
<enum>QAbstractItemView::SingleSelection</enum>
|
||||
</property>
|
||||
<property name="resizeMode">
|
||||
<enum>QListView::Adjust</enum>
|
||||
</property>
|
||||
<property name="wordWrap">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QDialogButtonBox" name="button_box">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
</property>
|
||||
<property name="standardButtons">
|
||||
<set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<resources/>
|
||||
<connections>
|
||||
|
@ -1,76 +0,0 @@
|
||||
#include "select_theme_impl.h"
|
||||
#include <QFile>
|
||||
#include <QIcon>
|
||||
#include <QDirIterator>
|
||||
#include <QSettings>
|
||||
#include <QApplication>
|
||||
#include <QAction>
|
||||
#include <QtGlobal>
|
||||
#include <QRegularExpression>
|
||||
#include <settings.h>
|
||||
|
||||
SelectThemeImpl::SelectThemeImpl()
|
||||
{
|
||||
user_icons_dir_path = QString(QDir::separator()).append("home")
|
||||
.append(QDir::separator().toLatin1()).append(qgetenv("USER"))
|
||||
.append(QDir::separator().toLatin1()).append(".icons")
|
||||
.append(QDir::separator().toLatin1());
|
||||
}
|
||||
|
||||
void SelectThemeImpl::set_theme(const QString& theme_name)
|
||||
{
|
||||
settings_set_variant(SETTING_app_active_theme, theme_name);
|
||||
apply_theme(theme_name);
|
||||
}
|
||||
|
||||
void SelectThemeImpl::apply_theme(QString theme_name)
|
||||
{
|
||||
QIcon::setThemeName(theme_name);
|
||||
settings_set_variant(SETTING_app_active_theme, theme_name);
|
||||
}
|
||||
|
||||
QStringList SelectThemeImpl::get_themes_from_dir(QString path_to_dir)
|
||||
{
|
||||
QDirIterator it(path_to_dir, QStringList(theme_file_name), QDir::Files | QDir::NoDotAndDotDot | QDir::NoSymLinks, QDirIterator::Subdirectories);
|
||||
|
||||
QStringList files;
|
||||
|
||||
while(it.hasNext())
|
||||
{
|
||||
files << it.next();
|
||||
}
|
||||
|
||||
return parse_theme_names(files);
|
||||
}
|
||||
|
||||
QStringList SelectThemeImpl::parse_theme_names(const QStringList & theme_path_list)
|
||||
{
|
||||
QRegularExpression regex(this->theme_name_regex_pattern);
|
||||
|
||||
QStringList result;
|
||||
|
||||
for (int i = 0; i < theme_path_list.size(); ++i)
|
||||
{
|
||||
QFile theme_file(theme_path_list.at(i));
|
||||
|
||||
if(!theme_file.open(QIODevice::ReadOnly | QIODevice::Text))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
auto matched_data = regex.match(theme_file.readAll(), 0, QRegularExpression::PartialPreferCompleteMatch).captured();
|
||||
|
||||
result << matched_data.mid(theme_name_regex_pattern.length() - 2);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
QStringList SelectThemeImpl::get_available_theme_list()
|
||||
{
|
||||
auto available_theme_paths = get_themes_from_dir(this->system_icons_dir_path);
|
||||
available_theme_paths.append(get_themes_from_dir(this->user_icons_dir_path));
|
||||
available_theme_paths.append(get_themes_from_dir(this->app_theme_path));
|
||||
|
||||
return available_theme_paths;
|
||||
}
|
@ -1,32 +0,0 @@
|
||||
#ifndef QUERY_THEME_IMPL_H
|
||||
#define QUERY_THEME_IMPL_H
|
||||
#include <QString>
|
||||
#include <QMenu>
|
||||
#include <QDir>
|
||||
#include <console_widget/console_impl.h>
|
||||
|
||||
class SelectThemeImpl
|
||||
{
|
||||
public:
|
||||
SelectThemeImpl();
|
||||
void apply_theme(QString theme_name);
|
||||
QStringList get_available_theme_list();
|
||||
|
||||
private slots:
|
||||
void set_theme(const QString& themeName);
|
||||
|
||||
private:
|
||||
QStringList parse_theme_names(const QStringList & theme_path_list);
|
||||
QStringList get_themes_from_dir(QString path_to_dir);
|
||||
|
||||
QMenu * menu_theme;
|
||||
|
||||
const QString app_theme_path = ":/icons";
|
||||
const QString system_icons_dir_path = "/usr/share/icons";
|
||||
QString user_icons_dir_path;
|
||||
|
||||
const QString theme_name_regex_pattern = "Name=.*";
|
||||
const QString theme_file_name = "index.theme";
|
||||
};
|
||||
|
||||
#endif // QUERY_THEME_IMPL_H
|
@ -35,7 +35,6 @@
|
||||
#include "console_impls/all_policies_folder_impl.h"
|
||||
#include "console_impls/query_folder_impl.h"
|
||||
#include "console_impls/query_item_impl.h"
|
||||
#include "console_impls/select_theme_impl.h"
|
||||
#include "console_widget/console_widget.h"
|
||||
#include "attribute_edits/country_combo.h"
|
||||
#include "globals.h"
|
||||
@ -371,7 +370,7 @@ void MainWindow::open_manual() {
|
||||
}
|
||||
|
||||
void MainWindow::open_choose_theme_dialog() {
|
||||
auto dialog = new ChooseThemeDialog (this);
|
||||
auto dialog = new ChooseThemeDialog(this);
|
||||
dialog->open();
|
||||
ui->toolbar->setFocus();
|
||||
}
|
||||
|
@ -22,7 +22,6 @@
|
||||
|
||||
#include "config.h"
|
||||
#include "connection_options_dialog.h"
|
||||
#include "console_impls/select_theme_impl.h"
|
||||
|
||||
#include <QAction>
|
||||
#include <QDialog>
|
||||
@ -77,7 +76,9 @@ void settings_setup_dialog_geometry(const QString setting, QDialog *dialog) {
|
||||
}
|
||||
|
||||
void settings_restore_themes() {
|
||||
SelectThemeImpl().apply_theme(settings_get_variant(SETTING_app_active_theme).toString());
|
||||
QString theme_name = settings_get_variant(SETTING_app_active_theme).toString();
|
||||
QIcon::setThemeName(theme_name);
|
||||
settings_set_variant(SETTING_app_active_theme, theme_name);
|
||||
}
|
||||
|
||||
bool settings_restore_geometry(const QString setting, QWidget *widget) {
|
||||
|
Loading…
Reference in New Issue
Block a user