provide basic Export functionality

work/spdx
Michail Vourlakos 4 years ago
parent 16c1a849b6
commit a8d4bdf82d

@ -578,6 +578,39 @@ ViewDelayedCreationData Storage::newView(const Layout::GenericLayout *destinatio
return result;
}
bool Storage::exportTemplate(const QString &originFile, const QString &destinationFile,const Data::AppletsTable &approvedApplets)
{
if (originFile.isEmpty() || !QFile(originFile).exists() || destinationFile.isEmpty()) {
return false;
}
if (QFile(destinationFile).exists()) {
QFile::remove(destinationFile);
}
QFile(originFile).copy(destinationFile);
KSharedConfigPtr destFilePtr = KSharedConfig::openConfig(destinationFile);
KConfigGroup containments = KConfigGroup(destFilePtr, "Containments");
for (const auto &cId : containments.groupList()) {
auto applets = containments.group(cId).group("Applets");
for (const auto &aId: applets.groupList()) {
QString pluginId = applets.group(aId).readEntry("plugin", "");
if (!approvedApplets.containsId(pluginId)) {
for (const auto &configId: applets.group(aId).groupList()) {
applets.group(aId).group(configId).deleteGroup();
}
}
}
}
containments.sync();
return true;
}
ViewDelayedCreationData Storage::copyView(const Layout::GenericLayout *layout, Plasma::Containment *containment)
{
if (!containment || !layout->corona()) {

@ -85,6 +85,8 @@ public:
ViewDelayedCreationData copyView(const Layout::GenericLayout *layout, Plasma::Containment *containment);
ViewDelayedCreationData newView(const Layout::GenericLayout *destination, const QString &templateFile);
bool exportTemplate(const QString &originFile, const QString &destinationFile, const Data::AppletsTable &approvedApplets);
/// STATIC
//! Check if an applet config group is valid or belongs to removed applet
static bool appletGroupIsValid(const KConfigGroup &appletGroup);

@ -197,6 +197,18 @@ void Applets::setSelected(const Latte::Data::AppletsTable &applets)
}
}
Latte::Data::AppletsTable Applets::selectedApplets()
{
Data::AppletsTable selected;
for(int i=0; i<c_applets.rowCount(); ++i) {
if (c_applets[i].isSelected) {
selected << c_applets[i];
}
}
return selected;
}
Qt::ItemFlags Applets::flags(const QModelIndex &index) const
{
const int column = index.column();

@ -73,6 +73,8 @@ public:
void setData(const Latte::Data::AppletsTable &applets);
void setSelected(const Latte::Data::AppletsTable &applets);
Latte::Data::AppletsTable selectedApplets();
void deselectAll();
void reset();
void selectAll();

@ -86,14 +86,17 @@ void ExportTemplateDialog::initButtons()
void ExportTemplateDialog::initExtractButton(const QString &tooltip)
{
QPushButton *extractBtn = new QPushButton(this);
extractBtn->setText(i18nc("export template", "Export"));
extractBtn->setIcon(QIcon::fromTheme("document-export"));
extractBtn->setToolTip(tooltip);
m_exportButton = new QPushButton(this);
m_exportButton->setText(i18nc("export template", "Export"));
m_exportButton->setIcon(QIcon::fromTheme("document-export"));
m_exportButton->setToolTip(tooltip);
m_ui->buttonBox->addButton(extractBtn, QDialogButtonBox::AcceptRole);
m_ui->buttonBox->addButton(m_exportButton, QDialogButtonBox::AcceptRole);
}
connect(extractBtn, &QPushButton::clicked, this, &ExportTemplateDialog::onCancel);
QPushButton *ExportTemplateDialog::exportButton() const
{
return m_exportButton;
}
void ExportTemplateDialog::onDataChanged()

@ -28,6 +28,7 @@
// Qt
#include <QDialog>
#include <QObject>
#include <QPushButton>
#include <QWindow>
namespace Ui {
@ -63,6 +64,8 @@ public:
Ui::ExportTemplateDialog *ui() const;
Latte::Corona *corona() const;
QPushButton *exportButton() const;
protected:
void accept() override;
@ -81,6 +84,8 @@ private:
bool m_isExportingLayout{false};
bool m_isExportingView{false};
QPushButton *m_exportButton{nullptr};
Latte::Corona *m_corona{nullptr};
Ui::ExportTemplateDialog *m_ui;

@ -102,6 +102,7 @@ void ExportTemplateHandler::init()
connect(m_ui->buttonBox->button(QDialogButtonBox::Reset), &QPushButton::clicked, this, &ExportTemplateHandler::reset);
connect(m_ui->chooseBtn, &QPushButton::clicked, this, &ExportTemplateHandler::chooseFileDialog);
connect(m_parentDialog->exportButton(), &QPushButton::clicked, this, &ExportTemplateHandler::onExport);
//! Labels
connect(this, &ExportTemplateHandler::filepathChanged, this, &ExportTemplateHandler::onFilepathChanged);
@ -119,6 +120,7 @@ void ExportTemplateHandler::setFilepath(const QString &filepath)
void ExportTemplateHandler::loadLayoutApplets(const QString &layoutName, const QString &layoutId)
{
m_originLayoutFilePath = layoutId;
Data::AppletsTable c_data = Latte::Layouts::Storage::self()->plugins(layoutId);
m_appletsModel->setData(c_data);
m_parentDialog->setWindowTitle(i18n("Export Layout Template"));
@ -177,6 +179,13 @@ void ExportTemplateHandler::chooseFileDialog()
chooseFileDlg->selectFile(currentFile.baseName());
}
void ExportTemplateHandler::onExport()
{
if (!m_originLayoutFilePath.isEmpty()) {
bool result = Latte::Layouts::Storage::self()->exportTemplate(m_originLayoutFilePath, c_filepath, m_appletsModel->selectedApplets());
}
}
void ExportTemplateHandler::onFilepathChanged()
{
QString filepath = c_filepath;

@ -91,6 +91,7 @@ private:
void setFilepath(const QString &filepath);
private slots:
void onExport();
void onFilepathChanged();
void onSelectAll();
void onDeselectAll();
@ -101,6 +102,8 @@ private:
QString c_filepath;
QString o_filepath;
QString m_originLayoutFilePath;
Dialog::ExportTemplateDialog *m_parentDialog{nullptr};
Ui::ExportTemplateDialog *m_ui{nullptr};

Loading…
Cancel
Save