//
//
-#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>
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;
QSettings().setValue("hostkey",key);
QSettings().setValue("hostname",hname);
}
+
+void MMainWindow::openOfficeCfg()
+{
+ MOfficeConfig c(this);
+ c.exec();
+}
void exportKey();
void importKey();
void generateKey();
+ void openOfficeCfg();
};
#endif
//
//
-#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:
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);
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();
}
/**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*/
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*/
--- /dev/null
+//
+// 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);
+}
--- /dev/null
+//
+// 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
labeldlg.cpp \
version.cpp \
templates.cpp \
- templatedlg.cpp
+ templatedlg.cpp \
+ office.cpp
HEADERS = \
keygen.h \
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.