lib

KoDocumentIface.cpp
1/* This file is part of the KDE project
2 Copyright (C) 2000 David Faure <faure@kde.org>
3
4 This library is free software; you can redistribute it and/or
5 modify it under the terms of the GNU Library General Public
6 License as published by the Free Software Foundation; either
7 version 2 of the License.
8
9 This library is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 Library General Public License for more details.
13
14 You should have received a copy of the GNU Library General Public License
15 along with this library; see the file COPYING.LIB. If not, write to
16 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17 * Boston, MA 02110-1301, USA.
18*/
19
20#include "KoDocument.h"
21#include "KoDocumentIface.h"
22#include "KoDocumentInfoDlg.h"
23#include "KoDocumentInfo.h"
24#include "KoView.h"
25#include <tdeapplication.h>
26#include <dcopclient.h>
27#include <kdcopactionproxy.h>
28#include <tdeaction.h>
29#include <kdebug.h>
30#include <kdcoppropertyproxy.h>
31
32//static
34{
35 static int s_docIFNumber = 0;
36 TQCString name; name.setNum( s_docIFNumber++ ); name.prepend("Document-");
37 return name;
38}
39
40KoDocumentIface::KoDocumentIface( KoDocument * doc, const char * name )
41 : DCOPObject( name ? TQCString(name) : newIfaceName() )
42{
43 m_pDoc = doc;
44 m_actionProxy = new KDCOPActionProxy( doc->actionCollection(), this );
45}
46
47KoDocumentIface::~KoDocumentIface()
48{
49 delete m_actionProxy;
50}
51
53{
54 m_pDoc->openURL( KURL( url ) );
55}
56
58{
59 return m_pDoc->isLoading();
60}
61
63{
64 return m_pDoc->url().url();
65}
66
68{
69 return m_pDoc->isModified();
70}
71
73{
74 return m_pDoc->viewCount();
75}
76
78{
79 TQPtrList<KoView> views = m_pDoc->views();
80 KoView *v = views.at( idx );
81 if ( !v )
82 return DCOPRef();
83
84 DCOPObject *obj = v->dcopObject();
85
86 if ( !obj )
87 return DCOPRef();
88
89 return DCOPRef( kapp->dcopClient()->appId(), obj->objId() );
90}
91
92DCOPRef KoDocumentIface::action( const TQCString &name )
93{
94 return DCOPRef( kapp->dcopClient()->appId(), m_actionProxy->actionObjectId( name ) );
95}
96
98{
99 QCStringList res;
100 TQValueList<TDEAction *> lst = m_actionProxy->actions();
101 TQValueList<TDEAction *>::ConstIterator it = lst.begin();
102 TQValueList<TDEAction *>::ConstIterator end = lst.end();
103 for (; it != end; ++it )
104 res.append( (*it)->name() );
105
106 return res;
107}
108
109TQMap<TQCString,DCOPRef> KoDocumentIface::actionMap()
110{
111 return m_actionProxy->actionMap();
112}
113
115{
116 m_pDoc->save();
117}
118
119void KoDocumentIface::saveAs( const TQString & url )
120{
121 m_pDoc->saveAs( KURL( url ) );
122 m_pDoc->waitSaveComplete(); // see ReadWritePart
123}
124
125void KoDocumentIface::setOutputMimeType( const TQCString & mimetype )
126{
127 m_pDoc->setOutputMimeType( mimetype );
128}
129
130TQString KoDocumentIface::documentInfoAuthorName() const
131{
132 KoDocumentInfo * info = m_pDoc->documentInfo();
133 KoDocumentInfoAuthor * authorPage = static_cast<KoDocumentInfoAuthor *>(info->page( "author" ));
134 if ( !authorPage )
135 {
136 kdWarning() << "Author information not found in documentInfo !" << endl;
137 return TQString();
138 }
139 else
140 return authorPage->fullName();
141}
142
143TQString KoDocumentIface::documentInfoEmail() const
144{
145 KoDocumentInfo * info = m_pDoc->documentInfo();
146 KoDocumentInfoAuthor * authorPage = static_cast<KoDocumentInfoAuthor *>(info->page( "author" ));
147 if ( !authorPage )
148 {
149 kdWarning() << "Author information not found in documentInfo !" << endl;
150 return TQString();
151 }
152 else
153 return authorPage->email();
154}
155
156TQString KoDocumentIface::documentInfoCompanyName() const
157{
158 KoDocumentInfo * info = m_pDoc->documentInfo();
159 KoDocumentInfoAuthor * authorPage = static_cast<KoDocumentInfoAuthor *>(info->page( "author" ));
160 if ( !authorPage )
161 {
162 kdWarning() << "Author information not found in documentInfo !" << endl;
163 return TQString();
164 }
165 else
166 return authorPage->company();
167}
168
169TQString KoDocumentIface::documentInfoTelephone() const
170{
171 kdDebug()<<" Keep compatibility with koffice <= 1.3 : use documentInfoTelephoneWork\n";
172 return documentInfoTelephoneWork();
173}
174
175TQString KoDocumentIface::documentInfoTelephoneWork() const
176{
177 KoDocumentInfo * info = m_pDoc->documentInfo();
178 KoDocumentInfoAuthor * authorPage = static_cast<KoDocumentInfoAuthor *>(info->page( "author" ));
179 if ( !authorPage )
180 {
181 kdWarning() << "Author information not found in documentInfo !" << endl;
182 return TQString();
183 }
184 else
185 return authorPage->telephoneWork();
186}
187
188TQString KoDocumentIface::documentInfoTelephoneHome() const
189{
190 KoDocumentInfo * info = m_pDoc->documentInfo();
191 KoDocumentInfoAuthor * authorPage = static_cast<KoDocumentInfoAuthor *>(info->page( "author" ));
192 if ( !authorPage )
193 {
194 kdWarning() << "Author information not found in documentInfo !" << endl;
195 return TQString();
196 }
197 else
198 return authorPage->telephoneHome();
199}
200
201
202TQString KoDocumentIface::documentInfoFax() const
203{
204 KoDocumentInfo * info = m_pDoc->documentInfo();
205 KoDocumentInfoAuthor * authorPage = static_cast<KoDocumentInfoAuthor *>(info->page( "author" ));
206 if ( !authorPage )
207 {
208 kdWarning() << "Author information not found in documentInfo !" << endl;
209 return TQString();
210 }
211 else
212 return authorPage->fax();
213
214}
215TQString KoDocumentIface::documentInfoCountry() const
216{
217 KoDocumentInfo * info = m_pDoc->documentInfo();
218 KoDocumentInfoAuthor * authorPage = static_cast<KoDocumentInfoAuthor *>(info->page( "author" ));
219 if ( !authorPage )
220 {
221 kdWarning() << "Author information not found in documentInfo !" << endl;
222 return TQString();
223 }
224 else
225 return authorPage->country();
226
227}
228TQString KoDocumentIface::documentInfoPostalCode() const
229{
230 KoDocumentInfo * info = m_pDoc->documentInfo();
231 KoDocumentInfoAuthor * authorPage = static_cast<KoDocumentInfoAuthor *>(info->page( "author" ));
232 if ( !authorPage )
233 {
234 kdWarning() << "Author information not found in documentInfo !" << endl;
235 return TQString();
236 }
237 else
238 return authorPage->postalCode();
239
240}
241TQString KoDocumentIface::documentInfoCity() const
242{
243 KoDocumentInfo * info = m_pDoc->documentInfo();
244 KoDocumentInfoAuthor * authorPage = static_cast<KoDocumentInfoAuthor *>(info->page( "author" ));
245 if ( !authorPage )
246 {
247 kdWarning() << "Author information not found in documentInfo !" << endl;
248 return TQString();
249 }
250 else
251 return authorPage->city();
252
253}
254
255TQString KoDocumentIface::documentInfoInitial() const
256{
257 KoDocumentInfo * info = m_pDoc->documentInfo();
258 KoDocumentInfoAuthor * authorPage = static_cast<KoDocumentInfoAuthor *>(info->page( "author" ));
259 if ( !authorPage )
260 {
261 kdWarning() << "Author information not found in documentInfo !" << endl;
262 return TQString();
263 }
264 else
265 return authorPage->initial();
266}
267
268TQString KoDocumentIface::documentInfoAuthorPostion() const
269{
270 KoDocumentInfo * info = m_pDoc->documentInfo();
271 KoDocumentInfoAuthor * authorPage = static_cast<KoDocumentInfoAuthor *>(info->page( "author" ));
272 if ( !authorPage )
273 {
274 kdWarning() << "Author information not found in documentInfo !" << endl;
275 return TQString();
276 }
277 else
278 return authorPage->position();
279}
280
281
282TQString KoDocumentIface::documentInfoStreet() const
283{
284 KoDocumentInfo * info = m_pDoc->documentInfo();
285 KoDocumentInfoAuthor * authorPage = static_cast<KoDocumentInfoAuthor *>(info->page( "author" ));
286 if ( !authorPage )
287 {
288 kdWarning() << "Author information not found in documentInfo !" << endl;
289 return TQString();
290 }
291 else
292 return authorPage->street();
293
294}
295
296TQString KoDocumentIface::documentInfoTitle() const
297{
298 KoDocumentInfo * info = m_pDoc->documentInfo();
299 KoDocumentInfoAbout * aboutPage = static_cast<KoDocumentInfoAbout *>(info->page( "about" ));
300 if ( !aboutPage )
301 {
302 kdWarning() << "'About' page not found in documentInfo !" << endl;
303 return TQString();
304 }
305 else
306 return aboutPage->title();
307
308}
309
310TQString KoDocumentIface::documentInfoAbstract() const
311{
312 KoDocumentInfo * info = m_pDoc->documentInfo();
313 KoDocumentInfoAbout * aboutPage = static_cast<KoDocumentInfoAbout *>(info->page( "about" ));
314 if ( !aboutPage )
315 {
316 kdWarning() << "'About' page not found in documentInfo !" << endl;
317 return TQString();
318 }
319 else
320 return aboutPage->abstract();
321}
322
323TQString KoDocumentIface::documentInfoKeywords() const
324{
325 KoDocumentInfo * info = m_pDoc->documentInfo();
326 KoDocumentInfoAbout * aboutPage = static_cast<KoDocumentInfoAbout *>(info->page( "about" ));
327 if ( !aboutPage )
328 {
329 kdWarning() << "'About' page not found in documentInfo !" << endl;
330 return TQString();
331 }
332 else
333 return aboutPage->keywords();
334}
335
336TQString KoDocumentIface::documentInfoSubject() const
337{
338 KoDocumentInfo * info = m_pDoc->documentInfo();
339 KoDocumentInfoAbout * aboutPage = static_cast<KoDocumentInfoAbout *>(info->page( "about" ));
340 if ( !aboutPage )
341 {
342 kdWarning() << "'About' page not found in documentInfo !" << endl;
343 return TQString();
344 }
345 else
346 return aboutPage->subject();
347}
348void KoDocumentIface::setDocumentInfoKeywords(const TQString & text )
349{
350 KoDocumentInfo * info = m_pDoc->documentInfo();
351 KoDocumentInfoAbout * aboutPage = static_cast<KoDocumentInfoAbout *>(info->page( "about" ));
352 if ( !aboutPage )
353 {
354 kdWarning() << "'About' page not found in documentInfo !" << endl;
355 }
356 else
357 aboutPage->setKeywords(text);
358}
359
360void KoDocumentIface::setDocumentInfoSubject(const TQString & text)
361{
362 KoDocumentInfo * info = m_pDoc->documentInfo();
363 KoDocumentInfoAbout * aboutPage = static_cast<KoDocumentInfoAbout *>(info->page( "about" ));
364 if ( !aboutPage )
365 {
366 kdWarning() << "'About' page not found in documentInfo !" << endl;
367 }
368 else
369 aboutPage->setSubject(text);
370}
371
372void KoDocumentIface::setDocumentInfoAuthorName(const TQString & text)
373{
374 KoDocumentInfo * info = m_pDoc->documentInfo();
375 KoDocumentInfoAuthor * authorPage = static_cast<KoDocumentInfoAuthor *>(info->page( "author" ));
376 if ( !authorPage )
377 {
378 kdWarning() << "Author information not found in documentInfo !" << endl;
379 }
380 else
381 authorPage->setFullName(text);
382
383}
384
385void KoDocumentIface::setDocumentInfoEmail(const TQString &text)
386{
387 KoDocumentInfo * info = m_pDoc->documentInfo();
388 KoDocumentInfoAuthor * authorPage = static_cast<KoDocumentInfoAuthor *>(info->page( "author" ));
389 if ( !authorPage )
390 {
391 kdWarning() << "Author information not found in documentInfo !" << endl;
392 }
393 else
394 authorPage->setEmail(text);
395}
396
397void KoDocumentIface::setDocumentInfoCompanyName(const TQString &text)
398{
399 KoDocumentInfo * info = m_pDoc->documentInfo();
400 KoDocumentInfoAuthor * authorPage = static_cast<KoDocumentInfoAuthor *>(info->page( "author" ));
401 if ( !authorPage )
402 {
403 kdWarning() << "Author information not found in documentInfo !" << endl;
404 }
405 else
406 authorPage->setCompany(text);
407}
408
409void KoDocumentIface::setDocumentInfoAuthorPosition(const TQString &text)
410{
411 KoDocumentInfo * info = m_pDoc->documentInfo();
412 KoDocumentInfoAuthor * authorPage = static_cast<KoDocumentInfoAuthor *>(info->page( "author" ));
413 if ( !authorPage )
414 {
415 kdWarning() << "Author information not found in documentInfo !" << endl;
416 }
417 else
418 authorPage->setPosition(text);
419}
420
421
422void KoDocumentIface::setDocumentInfoTelephone(const TQString &text)
423{
424 kdDebug()<<"Keep compatibility with koffice <= 1.3 : use setDocumentInfoTelephoneWork\n";
425 setDocumentInfoTelephoneWork(text);
426}
427
428void KoDocumentIface::setDocumentInfoTelephoneWork(const TQString &text)
429{
430 KoDocumentInfo * info = m_pDoc->documentInfo();
431 KoDocumentInfoAuthor * authorPage = static_cast<KoDocumentInfoAuthor *>(info->page( "author" ));
432 if ( !authorPage )
433 {
434 kdWarning() << "Author information not found in documentInfo !" << endl;
435 }
436 else
437 authorPage->setTelephoneWork(text);
438}
439
440void KoDocumentIface::setDocumentInfoTelephoneHome(const TQString &text)
441{
442 KoDocumentInfo * info = m_pDoc->documentInfo();
443 KoDocumentInfoAuthor * authorPage = static_cast<KoDocumentInfoAuthor *>(info->page( "author" ));
444 if ( !authorPage )
445 {
446 kdWarning() << "Author information not found in documentInfo !" << endl;
447 }
448 else
449 authorPage->setTelephoneHome(text);
450}
451
452
453void KoDocumentIface::setDocumentInfoFax(const TQString &text)
454{
455 KoDocumentInfo * info = m_pDoc->documentInfo();
456 KoDocumentInfoAuthor * authorPage = static_cast<KoDocumentInfoAuthor *>(info->page( "author" ));
457 if ( !authorPage )
458 {
459 kdWarning() << "Author information not found in documentInfo !" << endl;
460 }
461 else
462 authorPage->setFax(text);
463}
464
465void KoDocumentIface::setDocumentInfoCountry(const TQString &text)
466{
467 KoDocumentInfo * info = m_pDoc->documentInfo();
468 KoDocumentInfoAuthor * authorPage = static_cast<KoDocumentInfoAuthor *>(info->page( "author" ));
469 if ( !authorPage )
470 {
471 kdWarning() << "Author information not found in documentInfo !" << endl;
472 }
473 else
474 authorPage->setCountry(text);
475
476}
477
478void KoDocumentIface::setDocumentInfoTitle(const TQString & text)
479{
480 KoDocumentInfo * info = m_pDoc->documentInfo();
481 KoDocumentInfoAbout * aboutPage = static_cast<KoDocumentInfoAbout *>(info->page( "about" ));
482 if ( !aboutPage )
483 {
484 kdWarning() << "'About' page not found in documentInfo !" << endl;
485 }
486 else
487 aboutPage->setTitle(text);
488}
489
490void KoDocumentIface::setDocumentInfoPostalCode(const TQString &text)
491{
492 KoDocumentInfo * info = m_pDoc->documentInfo();
493 KoDocumentInfoAuthor * authorPage = static_cast<KoDocumentInfoAuthor *>(info->page( "author" ));
494 if ( !authorPage )
495 {
496 kdWarning() << "Author information not found in documentInfo !" << endl;
497 }
498 else
499 authorPage->setPostalCode(text);
500
501}
502
503
504void KoDocumentIface::setDocumentInfoCity(const TQString & text)
505{
506 KoDocumentInfo * info = m_pDoc->documentInfo();
507 KoDocumentInfoAuthor * authorPage = static_cast<KoDocumentInfoAuthor *>(info->page( "author" ));
508 if ( !authorPage )
509 {
510 kdWarning() << "Author information not found in documentInfo !" << endl;
511 }
512 else
513 authorPage->setCity(text);
514}
515
516void KoDocumentIface::setDocumentInfoInitial(const TQString & text)
517{
518 KoDocumentInfo * info = m_pDoc->documentInfo();
519 KoDocumentInfoAuthor * authorPage = static_cast<KoDocumentInfoAuthor *>(info->page( "author" ));
520 if ( !authorPage )
521 {
522 kdWarning() << "Author information not found in documentInfo !" << endl;
523 }
524 else
525 authorPage->setInitial(text);
526}
527
528
529void KoDocumentIface::setDocumentInfoStreet(const TQString &text)
530{
531 KoDocumentInfo * info = m_pDoc->documentInfo();
532 KoDocumentInfoAuthor * authorPage = static_cast<KoDocumentInfoAuthor *>(info->page( "author" ));
533 if ( !authorPage )
534 {
535 kdWarning() << "Author information not found in documentInfo !" << endl;
536 }
537 else
538 authorPage->setStreet(text);
539
540}
541
542
543void KoDocumentIface::setDocumentInfoAbstract(const TQString &text)
544{
545 KoDocumentInfo * info = m_pDoc->documentInfo();
546 KoDocumentInfoAbout * aboutPage = static_cast<KoDocumentInfoAbout *>(info->page( "about" ));
547 if ( !aboutPage )
548 {
549 kdWarning() << "'About' page not found in documentInfo !" << endl;
550 }
551 else
552 aboutPage->setAbstract(text);
553}
554
556{
557 return DCOPObject::functionsDynamic() + KDCOPPropertyProxy::functions( m_pDoc );
558}
559
560bool KoDocumentIface::processDynamic( const TQCString &fun, const TQByteArray &data,
561 TQCString& replyType, TQByteArray &replyData )
562{
563 if ( KDCOPPropertyProxy::isPropertyRequest( fun, m_pDoc ) )
564 return KDCOPPropertyProxy::processPropertyRequest( fun, data, replyType, replyData, m_pDoc );
565
566 return DCOPObject::processDynamic( fun, data, replyType, replyData );
567}
568
virtual bool processDynamic(const TQCString &fun, const TQByteArray &data, TQCString &replyType, TQByteArray &replyData)
TQCString objId() const
virtual QCStringList functionsDynamic()
virtual TDEActionCollection * actionCollection() const
QCStringList actions()
void saveAs(const TQString &url)
Saves the document under a new name.
void save()
Saves the document under its existing filename.
void openURL(TQString url)
Opens a document stored in url Warning: this is asynchronous.
TQString url()
Returns the URL for this document (empty, real URL, or internal one).
static TQCString newIfaceName()
Generate a name for this interface.
TQMap< TQCString, DCOPRef > actionMap()
DCOPRef view(int idx)
DCOPRef action(const TQCString &name)
DCOP-action proxy.
The KOffice document class.
Definition KoDocument.h:61
void setOutputMimeType(const TQCString &mimeType, int specialOutputFlag=0)
Set the format in which the document should be saved.
This class is used to display a KoDocument.
Definition KoView.h:58
virtual DCOPObject * dcopObject()
Return a DCOP interface for this view KOffice Applications are strongly recommended to reimplement th...
Definition KoView.cpp:699