1 /***************************************************************************
2 docdigest.cpp
3 -------------------
4 begin : Wed Mar 15 2006
5 copyright : (C) 2006 by Klaas Freitag
6 email : freitag@kde.org
7 ***************************************************************************/
8
9 /***************************************************************************
10 * *
11 * This program is free software; you can redistribute it and/or modify *
12 * it under the terms of the GNU General Public License as published by *
13 * the Free Software Foundation; either version 2 of the License, or *
14 * (at your option) any later version. *
15 * *
16 ***************************************************************************/
17
18 #include <QString>
19 #include <QLocale>
20 #include <QSqlQuery>
21
22 #include <kcontacts/addressee.h>
23
24 #include "docdigest.h"
25 #include "defaultprovider.h"
26 #include "format.h"
27 #include "kraftsettings.h"
28
DocDigest(dbID id,const QString & type,const QString & clientID)29 DocDigest::DocDigest( dbID id, const QString& type, const QString& clientID )
30 :mID(id), mType( type ), mClientId( clientID ), mLocale( "kraft" ),
31 _archDocLazyLoaded(false)
32 {
33
34 }
35
DocDigest()36 DocDigest::DocDigest()
37 :mLocale( "kraft" ), _archDocLazyLoaded(false)
38 {
39 }
40
date() const41 QString DocDigest::date() const
42 {
43 return Format::toDateString(mDate, KraftSettings::self()->dateFormat());
44 }
45
rawDate() const46 QDate DocDigest::rawDate() const
47 {
48 return mDate;
49 }
50
lastModified() const51 QString DocDigest::lastModified() const
52 {
53 const QString re = QString( "%1 %2").arg( Format::toDateString(mLastModified.date(), KraftSettings::self()->dateFormat()))
54 .arg(mLastModified.time().toString("hh:mm"));
55 return re;
56 }
57
archDocDigestList()58 ArchDocDigestList DocDigest::archDocDigestList()
59 {
60 if( !_archDocLazyLoaded ) {
61 const QString id(ident());
62
63 qDebug() << "Querying archdocs for document ident " << id;
64 QSqlQuery query;
65 query.prepare("SELECT archDocID, ident, printDate, state FROM archdoc WHERE"
66 " ident=:id ORDER BY printDate DESC" );
67 query.bindValue(":id", id);
68 query.exec();
69
70 while(query.next()) {
71 int archDocID = query.value(0).toInt();
72 const QString dbIdent = query.value(1).toString();
73 QDateTime printDateTime = query.value(2).toDateTime();
74 int state = query.value(3).toInt();
75 mArchDocs.append( ArchDocDigest( printDateTime, state, dbIdent, dbID(archDocID) ) );
76 }
77 _archDocLazyLoaded = true;
78 }
79 return mArchDocs;
80 }
81
addressee() const82 KContacts::Addressee DocDigest::addressee() const
83 {
84 return mContact;
85 }
setAddressee(const KContacts::Addressee & contact)86 void DocDigest::setAddressee( const KContacts::Addressee& contact )
87 {
88 mContact = contact;
89 }
90
91
92 /* *************************************************************************** */
93
DocDigestsTimeline()94 DocDigestsTimeline::DocDigestsTimeline()
95 :mMonth( 0 ), mYear( 0 )
96 {
97
98 }
99
DocDigestsTimeline(int m,int y)100 DocDigestsTimeline::DocDigestsTimeline( int m, int y )
101 :mMonth( m ), mYear( y )
102 {
103
104 }
105
setDigestList(const DocDigestList & list)106 void DocDigestsTimeline::setDigestList( const DocDigestList& list )
107 {
108 mDigests = list;
109 }
110