[prev in list] [next in list] [prev in thread] [next in thread]
List: kde-commits
Subject: playground/office/kraft/src
From: Klaas Freitag <freitag () suse ! de>
Date: 2010-03-14 22:35:43
Message-ID: 1268606143.700067.4609.nullmailer () svn ! kde ! org
[Download RAW message or body]
SVN commit 1103368 by freitag:
- make reportgenerator use Akonadi for both own and client address
- lots of small bugfixes
M +2 -2 CMakeLists.txt
M +0 -3 addressselection.cpp
M +17 -18 archdoc.cpp
M +4 -0 doctype.cpp
M +4 -1 kraftsettings.kcfg
M +5 -2 portal.cpp
M +4 -2 prefsdialog.cpp
M +55 -34 reportgenerator.cpp
M +0 -1 reportgenerator.h
M +12 -10 texttemplate.cpp
--- trunk/playground/office/kraft/src/CMakeLists.txt #1103367:1103368
@@ -1,5 +1,5 @@
-include_directories(${KDE4_INCLUDES} ${KDE4_INCLUDE_DIR} ${QT_INCLUDES} \
${CMAKE_CURRENT_BINARY_DIR} ) +include_directories(${KDE4_INCLUDES} \
${KDE4_INCLUDE_DIR} ${QT_INCLUDES} ${CMAKE_CURRENT_BINARY_DIR} \
${KDEPIMLIBS_INCLUDE_DIRS})
add_subdirectory(pics)
@@ -169,7 +169,7 @@
kde4_add_executable(kraft ${kraft_SRCS})
-target_link_libraries(kraft kraftcat akonadi-contact ${QT_AND_KDECORE_LIBS} \
${QT_QTSQL_LIBRARY} ${KDE4_KHTML_LIBS} ${KDE4_KDEUI_LIBS} ${KDEPIMLIBS_KABC_LIBS} \
${KDE4_KIO_LIBS} ctemplate pthread) +target_link_libraries(kraft kraftcat \
akonadi-contact ${QT_AND_KDECORE_LIBS} ${QT_QTSQL_LIBRARY} ${KDE4_KHTML_LIBS} \
${KDE4_KDEUI_LIBS} ${KDEPIMLIBS_KABC_LIBS} ${KDE4_KIO_LIBS} ctemplate pthread)
install(TARGETS kraft ${INSTALL_TARGETS_DEFAULT_ARGS})
--- trunk/playground/office/kraft/src/addressselection.cpp #1103367:1103368
@@ -71,9 +71,6 @@
connect( openAdrBook, SIGNAL(clicked() ), SLOT( slotOpenAddressBook() ) );
hbox->addStretch(4);
- if ( !Akonadi::Control::start( this ) ) {
- kError() << "Failed to start Akonadi!";
- }
connect( mTreeWidget, SIGNAL( currentItemChanged ( QTreeWidgetItem*, \
QTreeWidgetItem* )),
SLOT( slotSelectionChanged( QTreeWidgetItem*, QTreeWidgetItem* ) ) );
}
--- trunk/playground/office/kraft/src/archdoc.cpp #1103367:1103368
@@ -100,37 +100,36 @@
mArchDocID = id;
QSqlQuery q;
- q.prepare("SELECT archDocID, ident, docType, docDescription, clientAddress, \
clientUid, " // pos 0..5
- "salut, goodbye, printDate, date, pretext, posttext, country, language, \
" // pos 6..13
- "projectLabel,tax, reducedTax, state from archdoc WHERE archDocID=:id" \
); // pos 14..17 + q.prepare("SELECT archDocID, ident, docType, clientAddress, \
clientUid, " // pos 0..4 + "salut, goodbye, printDate, date, pretext, \
posttext, country, language, " // pos 5..12 + "projectLabel,tax, \
reducedTax, state from archdoc WHERE archDocID=:id" ); // pos 13..16 \
q.bindValue(":id", id.toInt()); q.exec();
kDebug() << "Loading document id " << id.toString() << endl;
if( q.next()) {
- kDebug() << "loading archived document with ident " << id.toString() << endl;
QString docID;
QString country;
QString lang;
docID = q.value( 0 ).toString();
mIdent = q.value( 1 ).toString();
mDocType = q.value( 2 ).toString();
- mAddress = q.value( 4 ).toString();
- mClientUid = q.value( 5 ).toString();
- mSalut = q.value( 6 ).toString();
- mGoodbye = q.value( 7 ).toString();
- QVariant v = q.value( 8 );
+ mAddress = q.value( 3 ).toString();
+ mClientUid = q.value( 4 ).toString();
+ mSalut = q.value( 5 ).toString();
+ mGoodbye = q.value( 6 ).toString();
+ QVariant v = q.value( 7 );
mPrintDate = v.toDateTime();
- mDate = q.value( 9 ).toDate();
- mPreText = KraftDB::self()->mysqlEuroDecode( q.value( 10 ).toString() );
- mPostText = KraftDB::self()->mysqlEuroDecode( q.value( 11 ).toString() );
- country = q.value( 12 ).toString();
- lang = q.value( 13 ).toString();
- mProjectLabel = q.value( 14 ).toString();
- mTax = q.value( 15 ).toDouble();
- mReducedTax = q.value( 16 ).toDouble();
- mState = q.value( 17 ).toInt();
+ mDate = q.value( 8 ).toDate();
+ mPreText = KraftDB::self()->mysqlEuroDecode( q.value( 9 ).toString() );
+ mPostText = KraftDB::self()->mysqlEuroDecode( q.value( 10 ).toString() );
+ country = q.value( 11 ).toString();
+ lang = q.value( 12 ).toString();
+ mProjectLabel = q.value( 13 ).toString();
+ mTax = q.value( 14 ).toDouble();
+ mReducedTax = q.value( 15 ).toDouble();
+ mState = q.value( 16 ).toInt();
KConfig *cfg = KGlobal::config().data();
mLocale.setCountry( country, cfg );
--- trunk/playground/office/kraft/src/doctype.cpp #1103367:1103368
@@ -202,6 +202,10 @@
QString tmplFile = name().toLower() + QString( ".trml" );
if ( mAttributes.hasAttribute( "docTemplateFile" ) ) {
tmplFile = mAttributes["docTemplateFile"].value().toString();
+ if( tmplFile.isEmpty() ) {
+ // happens in case of strange db content
+ tmplFile = "invoice.trml"; // the default doc
+ }
}
if ( tmplFile.contains( "/" ) && QFile::exists( tmplFile ) ) {
--- trunk/playground/office/kraft/src/kraftsettings.kcfg #1103367:1103368
@@ -82,7 +82,10 @@
</entry>
<entry name="ImportItemsFileName" type="String">
<label>The name of the last used input file for items.</label>
- </entry>
+ </entry>
+ <entry name="UserName" type="String">
+ <label>User name as reference to the KAddressbook to identify 'my' \
address.</label> + </entry>
</group>
<group name="document">
--- trunk/playground/office/kraft/src/portal.cpp #1103367:1103368
@@ -41,8 +41,7 @@
#include <kcmdlineargs.h>
#include <krun.h>
#include <kapplication.h>
-#include <kabc/addressbook.h>
-#include <kabc/stdaddressbook.h>
+#include <akonadi/control.h>
#include <kabc/addressee.h>
#include <ktoolinvocation.h>
@@ -258,6 +257,10 @@
{
QString dbName = DatabaseSettings::self()->dbDatabaseName();
+ if ( !Akonadi::Control::start( this ) ) {
+ kError() << "Failed to start Akonadi!";
+ }
+
SetupAssistant assi(this);
if( assi.init( SetupAssistant::Update) ) {
assi.exec();
--- trunk/playground/office/kraft/src/prefsdialog.cpp #1103367:1103368
@@ -134,7 +134,8 @@
{
mPrefsWages = new PrefsWages(this);
- KPageWidgetItem *topFrame = addPage( mPrefsWages, i18n( "Wages" ));
+ // KPageWidgetItem *topFrame =
+ (void) addPage( mPrefsWages, i18n( "Wages" ));
//topFrame->setIcon(KIcon( "accessories-text-editor" ) );
}
@@ -143,7 +144,8 @@
{
mPrefsUnits = new PrefsUnits(this);
- KPageWidgetItem *topFrame = addPage( mPrefsUnits, i18n( "Units" ));
+ // KPageWidgetItem *topFrame =
+ (void) addPage( mPrefsUnits, i18n( "Units" ));
//topFrame->setIcon(KIcon( "accessories-text-editor" ) );
}
--- trunk/playground/office/kraft/src/reportgenerator.cpp #1103367:1103368
@@ -133,12 +133,10 @@
{
mArchDoc = new ArchDoc(id);
- if( mArchDoc->clientUid().isEmpty() ) {
- addressReceived( 0 );
- } else {
- Akonadi::ContactSearchJob *job = new Akonadi::ContactSearchJob;
- connect( job, SIGNAL( result( KJob* ) ), SLOT( addressReceived( KJob* ) ) );
- }
+ // FIXME: Read all contacts, even if the customer is not in the address book
+ // we need to read all for our own address.
+ Akonadi::ContactSearchJob *job = new Akonadi::ContactSearchJob;
+ connect( job, SIGNAL( result( KJob* ) ), SLOT( addressReceived( KJob* ) ) );
}
// Result Slot of the Contact Search above
@@ -146,29 +144,45 @@
{
kDebug() << "Reading Akonadi Search Job!";
KABC::Addressee addressee ;
- if( job ) {
- if ( job->error() ) {
- qDebug() << "Akonadi Contact Job Read Error: " << job->errorString();
- return;
- }
+ KABC::Addressee myAddress;
- Akonadi::ContactSearchJob *searchJob = qobject_cast<Akonadi::ContactSearchJob*>( \
job );
- KABC::Addressee::List contacts = searchJob->contacts();
- kDebug() << "Amount of address entries: " << contacts.size();
+ if( ! job ) {
+ kError() << "Akonadi Address search job failed!";
+ return;
+ }
- // iterate over all found contacts and write build up the treeview
- foreach ( const KABC::Addressee &contact, contacts ) {
- if( contact.uid() == mArchDoc->clientUid() ) {
- addressee = contact;
- break;
- }
+ if ( job->error() ) {
+ qDebug() << "Akonadi Contact Job Read Error: " << job->errorString();
+ return;
+ }
+
+ QString myName = KraftSettings::self()->userName();
+ kDebug() << "MY name is " << myName;
+
+ Akonadi::ContactSearchJob *searchJob = qobject_cast<Akonadi::ContactSearchJob*>( \
job ); + KABC::Addressee::List contacts = searchJob->contacts();
+ kDebug() << "Amount of address entries: " << contacts.size();
+
+ // iterate over all found contacts and search for the customer address
+ // and 'My' address
+ foreach ( const KABC::Addressee &contact, contacts ) {
+ if( contact.uid() == mArchDoc->clientUid() ) {
+ addressee = contact;
}
+ kDebug() << "XXXXXXXXXX comparing " << contact.name() << " with " << myName;
+ if( contact.name() == myName ) {
+ myAddress = contact;
+ }
+ if( !( myAddress.isEmpty() || addressee.isEmpty() ) ) break;
}
QString tmplFile = findTemplate( mArchDoc->docType() );
if ( tmplFile.isEmpty() ) {
+ kDebug() << "tmplFile is emty!";
return;
+ } else {
+ kDebug() << "Reading this template: " << tmplFile;
}
// create a text template
@@ -276,21 +290,25 @@
tmpl.setValue( TAG( "VATSUM" ), mArchDoc->taxSum().toString( mArchDoc->locale() ) \
);
- // tmpl.setValue( TAG( "IMAGE" ), mArchDoc->
+ // My own contact data
- KABC::Addressee contact;
- // contact = KABC::StdAddressBook::self()->whoAmI();
+ tmpl.setValue( TAG( "MY_NAME" ), myAddress.realName() );
+ tmpl.setValue( TAG( "MY_ORGANISATION" ), myAddress.organization() );
+ tmpl.setValue( TAG( "MY_URL" ), myAddress.url().prettyUrl() );
+ tmpl.setValue( TAG( "MY_EMAIL" ), myAddress.preferredEmail() );
+ tmpl.setValue( TAG( "MY_PHONE" ), myAddress.phoneNumber( KABC::PhoneNumber::Work \
).number() ); + tmpl.setValue( TAG( "MY_FAX" ), myAddress.phoneNumber( \
KABC::PhoneNumber::Fax ).number() ); + tmpl.setValue( TAG( "MY_CELL" ), \
myAddress.phoneNumber( KABC::PhoneNumber::Cell ).number() );
- tmpl.setValue( TAG( "MY_NAME" ), contact.realName() );
- tmpl.setValue( TAG( "MY_ORGANISATION" ), contact.organization() );
- tmpl.setValue( TAG( "MY_URL" ), contact.url().prettyUrl() );
- tmpl.setValue( TAG( "MY_EMAIL" ), contact.preferredEmail() );
- tmpl.setValue( TAG( "MY_PHONE" ), contact.phoneNumber( KABC::PhoneNumber::Work \
).number() );
- tmpl.setValue( TAG( "MY_FAX" ), contact.phoneNumber( KABC::PhoneNumber::Fax \
).number() );
- tmpl.setValue( TAG( "MY_CELL" ), contact.phoneNumber( KABC::PhoneNumber::Cell \
).number() ); + KABC::Address address;
+ address = myAddress.address( KABC::Address::Pref );
+ if( address.isEmpty() )
+ address = myAddress.address(KABC::Address::Work );
+ if( address.isEmpty() )
+ address = myAddress.address(KABC::Address::Home );
+ if( address.isEmpty() )
+ address = myAddress.address(KABC::Address::Postal );
- KABC::Address address;
- address = contact.address( KABC::Address::Work );
tmpl.setValue( TAG( "MY_POSTBOX" ),
address.postOfficeBox() );
@@ -311,7 +329,10 @@
tmpl.setValue( TAG( "MY_LABEL" ),
address.label() );
- emit templateGenerated( tmpl.expand() );
+ QString output = tmpl.expand();
+
+ emit templateGenerated( output );
+
}
QString ReportGenerator::escapeTrml2pdfXML( const QString& str ) const
@@ -342,7 +363,7 @@
QString ReportGenerator::findTrml2Pdf( )
{
const QString rmlbinDefault = QString::fromLatin1( "trml2pdf" ); // FIXME: how to \
get the default value?
- QString rmlbin = KraftSettings::self()->self()->trml2PdfBinary();
+ QString rmlbin = KraftSettings::self()->trml2PdfBinary();
kDebug() << "### Start searching rml2pdf bin: " << rmlbin;
mHaveMerge = false;
--- trunk/playground/office/kraft/src/reportgenerator.h #1103367:1103368
@@ -30,7 +30,6 @@
class KJob;
class QFile;
-
class ReportGenerator : public QObject
{
Q_OBJECT
--- trunk/playground/office/kraft/src/texttemplate.cpp #1103367:1103368
@@ -21,7 +21,8 @@
#include <klocale.h>
#include <kdebug.h>
-#include <qfile.h>
+#include <QFile>
+#include <QFileInfo>
#include <string.h>
@@ -117,11 +118,10 @@
bool TextTemplate::openTemplate()
{
- QString findFile;
+ QFileInfo info( mFileName );
- if ( mFileName.contains( "/" ) ) {
+ if ( info.isAbsolute() ) {
// assume it is a absolute path
- findFile = mFileName;
} else {
KStandardDirs stdDirs;
if ( mFileName.isEmpty() ) {
@@ -129,18 +129,20 @@
return false;
}
- findFile = stdDirs.findResource( "data", mFileName );
+ QString findFile = stdDirs.findResource( "data", mFileName );
+ info.setFile( findFile );
}
- if ( findFile.isEmpty() || ! QFile::exists( findFile ) ) {
- mErrorString = i18n( "Could not find template file %1" ).arg( findFile );
+
+ if ( ! ( info.isFile() && info.isReadable() ) ) {
+ mErrorString = i18n( "Could not find template file %1" ).arg( \
info.absoluteFilePath() ); return false;
} else {
- mFileName = findFile;
+ mFileName = info.absoluteFilePath();
}
- kDebug() << "Loading this template source file: " << findFile << endl;
+ kDebug() << "Loading this template source file: " << mFileName << endl;
- Template *tmpl = Template::GetTemplate( std::string( findFile.toAscii().data() ), \
ctemplate::DO_NOT_STRIP ); + Template *tmpl = Template::GetTemplate( std::string( \
mFileName.toAscii().data() ), ctemplate::DO_NOT_STRIP ); tmpl->ReloadIfChanged();
if ( !tmpl || tmpl->state() != ctemplate::TS_READY ) {
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic