From: konrad Date: Sat, 29 Nov 2008 19:02:48 +0000 (+0000) Subject: make OOo more accessable X-Git-Url: http://git.silmor.de/gitweb/?a=commitdiff_plain;h=6a907cb14e9ac72ad26b58130c3709f2e68c56d2;p=web%2Fkonrad%2Fsmoke.git make OOo more accessable git-svn-id: https://silmor.de/svn/softmagic/smoke/trunk@205 6e3c4bff-ac9f-4ac1-96c5-d2ea494d3e33 --- diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index 95f2a24..bcfea4d 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -10,11 +10,12 @@ // // -#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 #include @@ -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(); +} diff --git a/src/mainwindow.h b/src/mainwindow.h index 619fcc4..b7282f0 100644 --- a/src/mainwindow.h +++ b/src/mainwindow.h @@ -53,6 +53,7 @@ class MMainWindow:public QMainWindow void exportKey(); void importKey(); void generateKey(); + void openOfficeCfg(); }; #endif diff --git a/src/odtrender.cpp b/src/odtrender.cpp index 15da178..3b09dfa 100644 --- a/src/odtrender.cpp +++ b/src/odtrender.cpp @@ -10,23 +10,20 @@ // // -#include "odtrender.h" #include "misc.h" +#include "odtrender.h" +#include "office.h" #include #include #include +#include #include #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"<, (C) 2008 +// +// Copyright: See README/COPYING files that come with this distribution +// +// + +#include "office.h" + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +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<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)")); + QListaprn=QPrinterInfo::availablePrinters(); + int cprn=0; + QString cp=set.value("officePrinter","").toString(); + for(int i=0;iaddItem(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 index 0000000..b340b41 --- /dev/null +++ b/src/office.h @@ -0,0 +1,47 @@ +// +// C++ Interface: office +// +// Description: Wrapper and Config Dialog around OpenOffice.org +// +// +// Author: Konrad Rosenbaum , (C) 2008 +// +// Copyright: See README/COPYING files that come with this distribution +// +// + +#ifndef MAGICSMOKE_OFFICE_H +#define MAGICSMOKE_OFFICE_H + +#include + +/**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 + +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 diff --git a/src/smoke.pro b/src/smoke.pro index 4786b53..c871282 100644 --- a/src/smoke.pro +++ b/src/smoke.pro @@ -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.