mirror of
https://github.com/arcan1s/awesome-widgets.git
synced 2025-04-24 15:37:23 +00:00
improve configuration import and export
Special directory for configuration store has been created. In particular it will allow to realize #72
This commit is contained in:
parent
5af4b0c40c
commit
162708295d
@ -394,6 +394,7 @@ Item {
|
||||
id: saveConfigAs
|
||||
selectExisting: false
|
||||
title: i18n("Export")
|
||||
folder: awConfig.configurationDirectory()
|
||||
onAccepted: {
|
||||
var status = awConfig.exportConfiguration(
|
||||
plasmoid.configuration,
|
||||
@ -431,6 +432,7 @@ Item {
|
||||
QtDialogs.FileDialog {
|
||||
id: openConfig
|
||||
title: i18n("Import")
|
||||
folder: awConfig.configurationDirectory()
|
||||
onAccepted: importSelection.open()
|
||||
}
|
||||
|
||||
|
@ -40,6 +40,25 @@ AWConfigHelper::~AWConfigHelper()
|
||||
}
|
||||
|
||||
|
||||
QString AWConfigHelper::configurationDirectory() const
|
||||
{
|
||||
// get readable directory
|
||||
QString localDir = QString("%1/awesomewidgets/configs")
|
||||
.arg(QStandardPaths::writableLocation(
|
||||
QStandardPaths::GenericDataLocation));
|
||||
|
||||
// create directory and copy files from default settings
|
||||
QDir localDirectory;
|
||||
if ((!localDirectory.exists(localDir))
|
||||
&& (localDirectory.mkpath(localDir))) {
|
||||
qCInfo(LOG_AW) << "Created directory" << localDir;
|
||||
copyConfigs(localDir);
|
||||
}
|
||||
|
||||
return localDir;
|
||||
}
|
||||
|
||||
|
||||
bool AWConfigHelper::dropCache() const
|
||||
{
|
||||
QString fileName = QString("%1/awesomewidgets.ndx")
|
||||
@ -212,6 +231,28 @@ void AWConfigHelper::writeDataEngineConfiguration(
|
||||
}
|
||||
|
||||
|
||||
void AWConfigHelper::copyConfigs(const QString localDir) const
|
||||
{
|
||||
qCDebug(LOG_AW) << "Local directory" << localDir;
|
||||
|
||||
QStringList dirs = QStandardPaths::locateAll(
|
||||
QStandardPaths::GenericDataLocation, QString("awesomewidgets/configs"),
|
||||
QStandardPaths::LocateDirectory);
|
||||
for (auto dir : dirs) {
|
||||
if (dir == localDir)
|
||||
continue;
|
||||
QStringList files = QDir(dir).entryList(QDir::Files);
|
||||
for (auto source : files) {
|
||||
QString destination = QString("%1/%2").arg(localDir).arg(source);
|
||||
bool status = QFile::copy(QString("%1/%2").arg(dir).arg(source),
|
||||
destination);
|
||||
qCInfo(LOG_AW) << "File" << source << "has been copied to"
|
||||
<< destination << "with status" << status;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void AWConfigHelper::copyExtensions(const QString item, const QString type,
|
||||
QSettings &settings,
|
||||
const bool inverse) const
|
||||
|
@ -32,6 +32,7 @@ class AWConfigHelper : public QObject
|
||||
public:
|
||||
explicit AWConfigHelper(QObject *parent = nullptr);
|
||||
virtual ~AWConfigHelper();
|
||||
Q_INVOKABLE QString configurationDirectory() const;
|
||||
Q_INVOKABLE bool dropCache() const;
|
||||
Q_INVOKABLE bool exportConfiguration(QObject *nativeConfig,
|
||||
const QString fileName) const;
|
||||
@ -46,6 +47,7 @@ public:
|
||||
|
||||
private:
|
||||
// methods
|
||||
void copyConfigs(const QString localDir) const;
|
||||
void copyExtensions(const QString item, const QString type,
|
||||
QSettings &settings, const bool inverse) const;
|
||||
void copySettings(QSettings &from, QSettings &to) const;
|
||||
|
@ -13,6 +13,7 @@ include_directories(
|
||||
file(GLOB SUBPROJECT_SOURCE *.cpp ${PROJECT_TRDPARTY_DIR}/qreplytimeout/*.cpp ${CMAKE_SOURCE_DIR}/*.cpp)
|
||||
file(GLOB SUBPROJECT_HEADER *.h ${PROJECT_TRDPARTY_DIR}/qreplytimeout/*.h)
|
||||
file(GLOB SUBPROJECT_UI *.ui)
|
||||
set(SUBPROJECT_CONFIGS ${CMAKE_CURRENT_SOURCE_DIR}/configs)
|
||||
set(SUBPROJECT_GRAPHITEMS ${CMAKE_CURRENT_SOURCE_DIR}/desktops)
|
||||
set(SUBPROJECT_QUOTES ${CMAKE_CURRENT_SOURCE_DIR}/quotes)
|
||||
set(SUBPROJECT_SCRIPTS ${CMAKE_CURRENT_SOURCE_DIR}/scripts)
|
||||
@ -29,6 +30,7 @@ add_library(${SUBPROJECT} STATIC ${SUBPROJECT_SOURCE} ${SUBPROJECT_HEADER} ${SUB
|
||||
target_link_libraries(${SUBPROJECT} ${Qt_LIBRARIES} ${Kf5_LIBRARIES})
|
||||
|
||||
# install
|
||||
install(DIRECTORY ${SUBPROJECT_CONFIGS} DESTINATION ${DATA_INSTALL_DIR}/${PROJECT_NAME})
|
||||
install(DIRECTORY ${SUBPROJECT_GRAPHITEMS} DESTINATION ${DATA_INSTALL_DIR}/${PROJECT_NAME})
|
||||
install(DIRECTORY ${SUBPROJECT_QUOTES} DESTINATION ${DATA_INSTALL_DIR}/${PROJECT_NAME})
|
||||
install(DIRECTORY ${SUBPROJECT_SCRIPTS} DESTINATION ${DATA_INSTALL_DIR}/${PROJECT_NAME})
|
||||
|
Loading…
Reference in New Issue
Block a user