[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-commits
Subject:    [kmymoney] kmymoney: Fix the report stylesheet and export.
From:       Cristian_OneČ› <onet.cristian () gmail ! com>
Date:       2016-11-28 5:44:55
Message-ID: E1cBEkJ-0006tH-9V () code ! kde ! org
[Download RAW message or body]

Git commit 9ba7793d5fbf71aec295820bd4d0c1c9a4c99b74 by Cristian OneČ›.
Committed on 28/11/2016 at 05:44.
Pushed by conet into branch 'master'.

Fix the report stylesheet and export.

While migrating from KDE4 it is possible to end up with a css file
setting which does not exist anymore so check the file's existence
before returning it as valid.

The export functionality was using KFileDialog to add a checkbox that
would control css inclusion. Now QFileDialog is used and the css is
always included. The related dead code was removed. An alternative
would be to use KFileWidget inside a QDialog but that code would be
too verbose and the value gained would not worth it (I'm not even
sure what can be achieved by not including the CSS but it can be moved
as a global option if it is necessary).

M  +2    -2    kmymoney/reports/reporttable.cpp
M  +21   -126  kmymoney/views/kreportsview.cpp
M  +1    -17   kmymoney/views/kreportsview.h

https://commits.kde.org/kmymoney/9ba7793d5fbf71aec295820bd4d0c1c9a4c99b74

diff --git a/kmymoney/reports/reporttable.cpp b/kmymoney/reports/reporttable.cpp
index b661f99..1acec56 100644
--- a/kmymoney/reports/reporttable.cpp
+++ b/kmymoney/reports/reporttable.cpp
@@ -47,12 +47,12 @@ QString reports::ReportTable::cssFileNameGet()
     cssfilename = KMyMoneyUtils::findResource(QStandardPaths::DataLocation, \
m_resourceHtml + '/' + MyMoneyFile::instance()->value(m_reportStyleSheet));  }
 
-  if (cssfilename.isEmpty()) {
+  if (cssfilename.isEmpty() || !QFile::exists(cssfilename)) {
     // if no report specific stylesheet was found, try to use the configured one
     cssfilename = KMyMoneyGlobalSettings::cssFileDefault();
   }
 
-  if (cssfilename.isEmpty()) {
+  if (cssfilename.isEmpty() || !QFile::exists(cssfilename)) {
     // if there still is nothing, try to use the installation default
     cssfilename = KMyMoneyUtils::findResource(QStandardPaths::DataLocation, \
m_resourceHtml + '/' + m_cssFileDefault);  }
diff --git a/kmymoney/views/kreportsview.cpp b/kmymoney/views/kreportsview.cpp
index c9c9a12..b7cdc01 100644
--- a/kmymoney/views/kreportsview.cpp
+++ b/kmymoney/views/kreportsview.cpp
@@ -37,13 +37,17 @@
 #include <QIcon>
 #include <QUrlQuery>
 #include <QFileInfo>
+#include <QFileDialog>
+#include <QLocale>
+#include <QTextCodec>
 
 // ----------------------------------------------------------------------------
 // KDE Includes
 
-#include <khtmlview.h>
-#include <kconfig.h>
-#include <kmessagebox.h>
+#include <KHTMLView>
+#include <KConfig>
+#include <KMessageBox>
+#include <KRecentDirs>
 
 // ----------------------------------------------------------------------------
 // Project Includes
@@ -102,8 +106,7 @@ KReportsView::KReportTab::KReportTab(QTabWidget* parent, const \
MyMoneyReport& re  parent->setTabEnabled(parent->indexOf(this), true);
 
   // get users character set encoding
-  // TODO: port to kf5
-  //m_encoding = KLocale::global()->encoding();
+  m_encoding = QTextCodec::codecForLocale()->name();
 }
 
 KReportsView::KReportTab::~KReportTab()
@@ -228,66 +231,8 @@ void KReportsView::KReportTab::toggleChart()
   * KReportsView Implementation
   */
 
-class KReportsView::Private
-{
-public:
-
-  Private() {
-    fSavProps = new FileSaveProperties();
-  }
-
-  ~Private() {
-    delete fSavProps;
-  }
-
-  class FileSaveProperties
-  {
-  public:
-    FileSaveProperties() {
-      includeCssCheckBox = 0;
-      cbIsChecked = true;
-      filter = "*.csv";
-      filtCsv = "*.csv|" + i18nc("CSV (Filefilter)", "CSV files");
-      filtHtml = "*.html|" + i18nc("HTML (Filefilter)", "HTML files");
-    }
-
-    /**
-     * 'include css' checkbox for file save dialog.
-     */
-    QCheckBox* includeCssCheckBox;
-
-    /**
-     * Persistent checked-state of includeCssCheckBox.
-     */
-    bool cbIsChecked;
-
-    /**
-     * Current filtername of file save dialog
-     * without description, e.g. @c '*.csv'
-     */
-    QString filter;
-
-    /**
-     * CSV filtername and description.
-     *
-     * @see KFileDialog::KFileDialog
-     */
-    QString filtCsv;
-
-    /**
-     * HTML filtername and description.
-     *
-     * @see KFileDialog::KFileDialog
-     */
-    QString filtHtml;
-  };
-
-  FileSaveProperties* fSavProps;
-};
-
 KReportsView::KReportsView(QWidget *parent, const char *name) :
     KMyMoneyViewBase(parent, name, i18n("Reports")),
-    d(new Private),
     m_needReload(false),
     m_reportListView(0)
 {
@@ -343,11 +288,6 @@ KReportsView::KReportsView(QWidget *parent, const char *name) :
   connect(MyMoneyFile::instance(), SIGNAL(dataChanged()), this, \
SLOT(slotLoadView()));  }
 
-KReportsView::~KReportsView()
-{
-  delete d;
-}
-
 void KReportsView::showEvent(QShowEvent * event)
 {
   emit aboutToShow();
@@ -683,66 +623,21 @@ void KReportsView::slotSaveView()
 {
   KReportTab* tab = dynamic_cast<KReportTab*>(m_reportTabWidget->currentWidget());
   if (tab) {
-    d->fSavProps->includeCssCheckBox = new QCheckBox(i18n("Include Stylesheet"));
-    // restore checkbox checked state
-    d->fSavProps->includeCssCheckBox->setChecked(d->fSavProps->cbIsChecked);
-
-    QString filterList = d->fSavProps->filtCsv + '\n' + d->fSavProps->filtHtml;
-    // TODO: port to kf5
-#if 0
-    QPointer<KFileDialog> dlg =
-      new KFileDialog(QUrl("kfiledialog:///kmymoney-export"), filterList, this,
-                      qobject_cast<QWidget*>(d->fSavProps->includeCssCheckBox));
-
-    connect(dlg, SIGNAL(filterChanged(QString)),
-            this, SLOT(slotSaveFilterChanged(QString)));
-
-    dlg->setOperationMode(KFileDialog::Saving);
-    dlg->setWindowTitle(i18n("Export as"));
-
-    // set current file filter && enable or disable includeCssCheckBox
-    KFileFilterCombo* combo = dlg->filterWidget();
-    if (d->fSavProps->filter == "*.csv") {
-      combo->setCurrentFilter(d->fSavProps->filtCsv);
-      d->fSavProps->includeCssCheckBox->setEnabled(false);
-    } else {
-      combo->setCurrentFilter(d->fSavProps->filtHtml);
-      d->fSavProps->includeCssCheckBox->setEnabled(true);
-    }
-
-    if (dlg->exec() == QDialog::Accepted) {
-      QUrl newURL = dlg->selectedUrl();
-      if (!newURL.isEmpty()) {
-        QString newName = newURL.toDisplayString(QUrl::PreferLocalFile);
-
-        if (newName.indexOf('.') == -1)
-          newName.append(".html");
-
-        // save checkbox checked state
-        d->fSavProps->cbIsChecked = d->fSavProps->includeCssCheckBox->isChecked();
-
-        try {
-          tab->saveAs(newName, d->fSavProps->includeCssCheckBox->isEnabled()
-                      && d->fSavProps->includeCssCheckBox->isChecked());
-        } catch (const MyMoneyException &e) {
-          KMessageBox::error(this, i18n("Failed to save: %1", e.what()));
-        }
+    QString filterList = i18nc("CSV (Filefilter)", "CSV files") + " (*.csv)"  + ";;" \
+ i18nc("HTML (Filefilter)", "HTML files") + " (*.html)"; +    QUrl newURL = \
QFileDialog::getSaveFileUrl(this, i18n("Export as"), \
QUrl::fromLocalFile(KRecentDirs::dir(":kmymoney-export")), filterList, \
&m_selectedExportFilter); +    if (!newURL.isEmpty()) {
+      KRecentDirs::add(":kmymoney-export", newURL.adjusted(QUrl::RemoveFilename | \
QUrl::StripTrailingSlash).path()); +      QString newName = \
newURL.toDisplayString(QUrl::PreferLocalFile); +
+      if (newName.indexOf('.') == -1)
+        newName.append(".html");
+
+      try {
+        tab->saveAs(newName, true);
+      } catch (const MyMoneyException &e) {
+        KMessageBox::error(this, i18n("Failed to save: %1", e.what()));
       }
     }
-    delete d->fSavProps->includeCssCheckBox;
-    delete dlg;
-#endif
-  }
-}
-
-void KReportsView::slotSaveFilterChanged(const QString& filter)
-{
-  d->fSavProps->filter = filter;
-
-  if (filter ==  "*.html") {
-    d->fSavProps->includeCssCheckBox->setEnabled(true);
-  } else {
-    d->fSavProps->includeCssCheckBox->setEnabled(false);
   }
 }
 
diff --git a/kmymoney/views/kreportsview.h b/kmymoney/views/kreportsview.h
index 966a187..3e6dec1 100644
--- a/kmymoney/views/kreportsview.h
+++ b/kmymoney/views/kreportsview.h
@@ -156,11 +156,6 @@ public:
   };
 
 private:
-  /// \internal d-pointer class.
-  class Private;
-  /// \internal d-pointer instance.
-  Private* const d;
-
   bool m_needReload;
 
   QListWidget* m_reportListView;
@@ -169,6 +164,7 @@ private:
   QVBoxLayout* m_listTabLayout;
   QTreeWidget* m_tocTreeWidget;
   QMap<QString, TocItemGroup*> m_allTocItemGroups;
+  QString m_selectedExportFilter;
 
   bool m_columnsAlreadyAdjusted;
 
@@ -188,15 +184,6 @@ public:
   explicit KReportsView(QWidget *parent = 0, const char *name = 0);
 
   /**
-    * Standard destructor.
-    *
-    * @return Nothing.
-    *
-    * @see KReportsView
-    */
-  ~KReportsView();
-
-  /**
     * Overridden so we can reload the view if necessary.
     *
     * @return Nothing.
@@ -233,9 +220,6 @@ public slots:
   void slotNewFromList();
   void slotDeleteFromList();
 
-protected slots:
-  void slotSaveFilterChanged(const QString&);
-
 signals:
   /**
     * This signal is emitted whenever a report is selected


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic