make OOo more accessable
authorkonrad <konrad@6e3c4bff-ac9f-4ac1-96c5-d2ea494d3e33>
Sat, 29 Nov 2008 19:02:48 +0000 (19:02 +0000)
committerkonrad <konrad@6e3c4bff-ac9f-4ac1-96c5-d2ea494d3e33>
Sat, 29 Nov 2008 19:02:48 +0000 (19:02 +0000)
git-svn-id: https://silmor.de/svn/softmagic/smoke/trunk@205 6e3c4bff-ac9f-4ac1-96c5-d2ea494d3e33

src/mainwindow.cpp
src/mainwindow.h
src/odtrender.cpp
src/odtrender.h
src/office.cpp [new file with mode: 0644]
src/office.h [new file with mode: 0644]
src/smoke.pro

index 95f2a24..bcfea4d 100644 (file)
 //
 //
 
-#include "mainwindow.h"
 #include "keygen.h"
-#include "webrequest.h"
-#include "overview.h"
 #include "main.h"
+#include "mainwindow.h"
+#include "office.h"
+#include "overview.h"
+#include "webrequest.h"
 
 #include <QByteArray>
 #include <QCheckBox>
@@ -52,6 +53,8 @@ MMainWindow::MMainWindow()
        m->addAction(tr("&Export Host Key..."),this,SLOT(exportKey()));
        m->addAction(tr("&Import Host Key..."),this,SLOT(importKey()));
        m->addAction(tr("&Generate Host Key..."),this,SLOT(generateKey()));
+       m->addSeparator();
+       m->addAction(tr("&OpenOffice.org Settings..."),this,SLOT(openOfficeCfg()));
        
        //create central widget
        QWidget *loginwidget;
@@ -323,3 +326,9 @@ void MMainWindow::importKey()
        QSettings().setValue("hostkey",key);
        QSettings().setValue("hostname",hname);
 }
+
+void MMainWindow::openOfficeCfg()
+{
+       MOfficeConfig c(this);
+       c.exec();
+}
index 619fcc4..b7282f0 100644 (file)
@@ -53,6 +53,7 @@ class MMainWindow:public QMainWindow
                void exportKey();
                void importKey();
                void generateKey();
+               void openOfficeCfg();
 };
 
 #endif
index 15da178..3b09dfa 100644 (file)
 //
 //
 
-#include "odtrender.h"
 #include "misc.h"
+#include "odtrender.h"
+#include "office.h"
 
 #include <QDir>
 #include <QFile>
 #include <QProcess>
+#include <QSettings>
 #include <QTemporaryFile>
 
 #include "zip/qunzip.h"
 #include "zip/qzip.h"
 
 
-QString MOdtRenderer::openOfficePath(){return officepath;}
-void MOdtRenderer::setOpenOfficePath(QString p){officepath=p;}
-QString MOdtRenderer::officepath="soffice";
-
-
 class MOdtRendererPrivate
 {
        protected:
@@ -36,15 +33,17 @@ class MOdtRendererPrivate
                MOdtRendererPrivate(QString file,MOdtRenderer*p);
                ~MOdtRendererPrivate();
                
-               void render(QIODevice*);
-               
-               QString render(QString);
+               bool renderToFile(QFile&);
                
                //data the parent uses
                QString extension;
                
        private:
                //methods that the parent does not call
+               void render(QIODevice*);
+               
+               QString render(QString);
+               
                QString renderLine(QString,QString,int);
                
                QString getVariable(QString varname);
@@ -93,29 +92,33 @@ void MOdtRenderer::renderToFile(QString file)
 
 void MOdtRenderer::renderToFile(QFile &file)
 {
-       qDebug("File Name: %s",file.fileName().toAscii().data());
+       if(d->renderToFile(file))
+               if(QSettings().value("doOpenODFs",false).toBool())
+                       openOfficeFile(file.fileName());
+}
+bool MOdtRendererPrivate::renderToFile(QFile &file)
+{
        if(!file.isWritable())
-               if(!file.open(QIODevice::ReadWrite))return;
+               if(!file.open(QIODevice::ReadWrite))return false;
        file.seek(0);
        file.resize(0);
-       d->render(&file);
+       render(&file);
+       return true;
 }
 
 void MOdtRenderer::renderToPrinter()
 {
        //generate temporary file
        QTemporaryFile tfile;
-       tfile.setAutoRemove(false);
+       tfile.setAutoRemove(false);//we don't want it to be auto-deleted on close()
        tfile.setFileTemplate(QDir::tempPath()+"/msmoke_XXXXXX."+d->extension);
        tfile.open();
        QString tname=tfile.fileName();
        //render
-       renderToFile(tfile);
+       d->renderToFile(tfile);
        tfile.close();
        //call ooffice and print
-       QProcess proc;
-       proc.start(officepath,QStringList()<<"-p"<<tname);
-       proc.waitForFinished();
+       printOfficeFile(tname);
        //remove temporary file
        QFile(tname).remove();
 }
index 7dc7c62..ce7313f 100644 (file)
@@ -39,12 +39,6 @@ class MOdtRenderer
                /**starts the internal rendering routine and outputs to printer (calls OpenOffice to print)*/
                virtual void renderToPrinter();
                
-               /**returns the currently configured path to OpenOffice*/
-               static QString openOfficePath();
-               
-               /**sets the path to OpenOffice*/
-               static void setOpenOfficePath(QString);
-               
        protected:
                friend class MOdtRendererPrivate;
                /**implement this to return the value of a variable during rendering; should return empty string if the variable does not exist*/
@@ -57,7 +51,6 @@ class MOdtRenderer
                virtual QString getLoopVariable(QString loopname,int iteration,QString varname,int addval)=0;
        private:
                MOdtRendererPrivate*d;
-               static QString officepath;
 };
 
 /**generic class that implements MOdtRenderer by calling signals; the signals must be connected using a direct or blocking connection; if any of them is not used it will behave as if the variable/loop did not exist*/
diff --git a/src/office.cpp b/src/office.cpp
new file mode 100644 (file)
index 0000000..703da62
--- /dev/null
@@ -0,0 +1,126 @@
+//
+// C++ Implementation: office
+//
+// Description: 
+//
+//
+// Author: Konrad Rosenbaum <konrad@silmor.de>, (C) 2008
+//
+// Copyright: See README/COPYING files that come with this distribution
+//
+//
+
+#include "office.h"
+
+#include <QBoxLayout>
+#include <QCheckBox>
+#include <QComboBox>
+#include <QFileDialog>
+#include <QFileInfo>
+#include <QGroupBox>
+#include <QLabel>
+#include <QLineEdit>
+#include <QPrinterInfo>
+#include <QProcess>
+#include <QPushButton>
+#include <QSettings>
+
+static QString getofficepath()
+{
+       return QSettings().value("officePath","soffice").toString();
+}
+
+void openOfficeFile(QString fname)
+{
+       //calculate parameters
+       QStringList r;
+       if(QSettings().value("officeViewOnly",false).toBool())r<<"-view";
+       r<<fname;
+       //open
+       QProcess::startDetached(getofficepath(),r);
+}
+
+void printOfficeFile(QString fname)
+{
+       //calculate parameters
+       QStringList r;
+       QString p=QSettings().value("officePrinter","").toString();
+       if(p=="")r<<"-p";
+       else r<<"-pt"<<p;
+       r<<fname;
+       //print and wait for finish
+       QProcess proc;
+       proc.start(getofficepath(),r);
+       proc.waitForFinished();
+}
+
+MOfficeConfig::MOfficeConfig(QWidget*par)
+       :QDialog(par)
+{
+       setWindowTitle(tr("Configure OpenOffice.org Access"));
+       
+       QVBoxLayout*vl,*vl2;
+       setLayout(vl=new QVBoxLayout);
+       QSettings set;
+       
+       QGroupBox*gb;
+       QHBoxLayout*hl;
+       QPushButton*p;
+       
+       vl->addWidget(gb=new QGroupBox(tr("OpenOffice.org")));
+       gb->setLayout(hl=new QHBoxLayout);
+       hl->addWidget(new QLabel(tr("Path to Executable:")));
+       hl->addWidget(oopath=new QLineEdit(set.value("officePath","soffice").toString()),1);
+       hl->addWidget(p=new QPushButton(tr("...","select OpenOffice path button")));
+       connect(p,SIGNAL(clicked()),this,SLOT(selectpath()));
+       
+       vl->addWidget(gb=new QGroupBox(tr("Printing ODF")));
+       gb->setLayout(hl=new QHBoxLayout);
+       hl->addWidget(new QLabel(tr("Printer:")));
+       hl->addWidget(printer=new QComboBox,1);
+       printer->setEditable(false);
+       printer->addItem(tr("(Default Printer)"));
+       QList<QPrinterInfo>aprn=QPrinterInfo::availablePrinters();
+       int cprn=0;
+       QString cp=set.value("officePrinter","").toString();
+       for(int i=0;i<aprn.size();i++){
+               QString s=aprn[i].printerName();
+               printer->addItem(s);
+               if(cp==s)cprn=i+1;
+       }
+       printer->setCurrentIndex(cprn);
+       
+       vl->addWidget(gb=new QGroupBox(tr("Opening ODF")));
+       gb->setLayout(vl2=new QVBoxLayout);
+       vl2->addWidget(viewonly=new QCheckBox(tr("Always open as Read-Only")));
+       viewonly->setChecked(set.value("officeViewOnly",false).toBool());
+       vl2->addWidget(doopen=new QCheckBox(tr("Automatically open all newly created files")));
+       doopen->setChecked(set.value("doOpenODFs",false).toBool());
+       
+       vl->addSpacing(15);
+       vl->addLayout(hl=new QHBoxLayout);
+       hl->addStretch(1);
+       hl->addWidget(p=new QPushButton(tr("OK")));
+       connect(p,SIGNAL(clicked()),this,SLOT(accept()));
+       connect(p,SIGNAL(clicked()),this,SLOT(savedata()));
+       hl->addWidget(p=new QPushButton(tr("Cancel")));
+       connect(p,SIGNAL(clicked()),this,SLOT(reject()));
+}
+
+void MOfficeConfig::savedata()
+{
+       QSettings set;
+       int cprn=printer->currentIndex();
+       if(cprn==0)set.setValue("officePrinter","");
+       else set.setValue("officePrinter",printer->currentText());
+       
+       set.setValue("officePath",oopath->text());
+       set.setValue("officeViewOnly",viewonly->isChecked());
+       set.setValue("doOpenODFs",doopen->isChecked());
+}
+
+void MOfficeConfig::selectpath()
+{
+       QString np=QFileDialog::getOpenFileName(this,tr("Select OpenOffice.org executable"),QFileInfo(oopath->text()).dir().absolutePath());
+       if(np!="")oopath->setText(np);
+}
diff --git a/src/office.h b/src/office.h
new file mode 100644 (file)
index 0000000..b340b41
--- /dev/null
@@ -0,0 +1,47 @@
+//
+// C++ Interface: office
+//
+// Description: Wrapper and Config Dialog around OpenOffice.org
+//
+//
+// Author: Konrad Rosenbaum <konrad@silmor.de>, (C) 2008
+//
+// Copyright: See README/COPYING files that come with this distribution
+//
+//
+
+#ifndef MAGICSMOKE_OFFICE_H
+#define MAGICSMOKE_OFFICE_H
+
+#include <QString>
+
+/**calls OpenOffice.org to open an ODF file*/
+void openOfficeFile(QString fname);
+
+/**calls OpenOffice.org to print an ODF file*/
+void printOfficeFile(QString fname);
+
+#include <QDialog>
+
+class QComboBox;
+class QCheckBox;
+class QLineEdit;
+
+/**configuration dialog for OpenOffice access*/
+class MOfficeConfig:public QDialog
+{
+       Q_OBJECT
+       public:
+               MOfficeConfig(QWidget*);
+               
+       private slots:
+               void savedata();
+               void selectpath();
+       private:
+               QComboBox*printer;
+               QCheckBox*viewonly,*doopen;
+               QLineEdit*oopath;
+};
+
+
+#endif
index 4786b53..c871282 100644 (file)
@@ -46,7 +46,8 @@ SOURCES = \
        labeldlg.cpp \
        version.cpp \
        templates.cpp \
-       templatedlg.cpp
+       templatedlg.cpp \
+       office.cpp
 
 HEADERS = \
        keygen.h \
@@ -71,7 +72,8 @@ HEADERS = \
        labeldlg.h \
        misc.h \
        templates.h \
-       templatedlg.h
+       templatedlg.h \
+       office.h
        
 #some PHP files are listed in this file to scan them for translatable items
 #use genphpscan.sh to regenerate it.