lib

KoTemplateChooseDia.cpp
1/* This file is part of the KDE project
2 Copyright (C) 1998, 1999 Reginald Stadlbauer <reggie@kde.org>
3 2000, 2001 Werner Trobin <trobin@kde.org>
4 2002, 2003 Thomas Nagy <tnagy@eleve.emn.fr>
5 2004 David Faure <faure@kde.org>
6
7 This library is free software; you can redistribute it and/or
8 modify it under the terms of the GNU Library General Public
9 License as published by the Free Software Foundation; either
10 version 2 of the License, or (at your option) any later version.
11
12 This library is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 Library General Public License for more details.
16
17 You should have received a copy of the GNU Library General Public License
18 along with this library; see the file COPYING.LIB. If not, write to
19 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
20 * Boston, MA 02110-1301, USA.
21 */
22
23// Description: Template Choose Dialog
24
25/******************************************************************/
26
27#include "KoTemplateChooseDia.h"
28
29#include <tdelocale.h>
30#include <tdefiledialog.h>
31#include <tdeinstance.h>
32#include <KoFilterManager.h>
33#include <KoTemplates.h>
34#include <KoDocument.h>
35#include <tdemainwindow.h>
36
37#include <kdebug.h>
38#include <kpushbutton.h>
39#include <kjanuswidget.h>
40#include <tdeglobalsettings.h>
41#include <ktextedit.h>
42#include <tdefileiconview.h>
43#include <tdefileitem.h>
44#include <tdemessagebox.h>
45#include <tdeapplication.h>
46#include <tdeaboutdata.h>
47
48#include <tqapplication.h>
49#include <tqlayout.h>
50#include <tqtabwidget.h>
51#include <tqcombobox.h>
52#include <tqcheckbox.h>
53#include <tqpoint.h>
54#include <tqobjectlist.h>
55#include <tqvgroupbox.h>
56#include <tqtooltip.h>
57
58class MyFileDialog : public KFileDialog
59{
60 public :
61 MyFileDialog(
62 const TQString& startDir=0,
63 const TQString& filter =0,
64 TQWidget *parent=0,
65 const char *name=0,
66 bool modal=0)
67 : KFileDialog (startDir, filter, parent, name, modal),
68 m_slotOkCalled( false ) {}
69
70 KURL currentURL()
71 {
72 setResult( TQDialog::Accepted ); // selectedURL tests for it
73 return KFileDialog::selectedURL();
74 }
75
76 // Return true if the current URL exists, show msg box if not
77 bool checkURL()
78 {
79 bool ok = true;
80 KURL url = currentURL();
81 if ( url.isLocalFile() )
82 {
83 ok = TQFile::exists( url.path() );
84 if ( !ok ) {
85 // Maybe offer to create a new document with that name? (see alos KoDocument::openFile)
86 KMessageBox::error( this, i18n( "The file %1 does not exist." ).arg( url.path() ) );
87 }
88 }
89 return ok;
90 }
91 // Called directly by pressing Return in the location combo
92 // (so we need to remember that it got called, to avoid calling it twice)
93 // Called "by hand" when clicking on our OK button
94 void slotOk() {
95 m_slotOkCalled = true;
96 KFileDialog::slotOk();
97 }
98 bool slotOkCalled() const { return m_slotOkCalled; }
99 protected:
100 // Typing a file that doesn't exist closes the file dialog, we have to
101 // handle this case better here.
102 virtual void accept() {
103 if ( checkURL() )
104 KFileDialog::accept();
105 }
106
107 virtual void reject() {
108 KFileDialog::reject();
109 emit cancelClicked();
110 }
111private:
112 bool m_slotOkCalled;
113};
114
115/*================================================================*/
116
117/*================================================================*/
118
119class KoTemplateChooseDiaPrivate {
120 public:
121 KoTemplateChooseDiaPrivate(const TQCString& templateType, TDEInstance* instance,
122 const TQCString &format,
123 const TQString &nativeName,
124 const TQStringList& extraNativeMimeTypes,
125 const KoTemplateChooseDia::DialogType &dialogType) :
126 m_templateType(templateType), m_instance(instance), m_format(format),
127 m_nativeName(nativeName), m_extraNativeMimeTypes( extraNativeMimeTypes ),
128 m_dialogType(dialogType), tree(0),
129 m_nostartupdlg( false ),
130 m_mainwidget(0), m_nodiag( 0 )
131 {
132 m_returnType = KoTemplateChooseDia::Empty;
133 }
134
135 ~KoTemplateChooseDiaPrivate() {}
136
137 TQCString m_templateType;
138 TDEInstance* m_instance;
139 TQCString m_format;
140 TQString m_nativeName;
141 TQStringList m_extraNativeMimeTypes;
142
144 KoTemplateTree *tree;
145
146 TQString m_templateName;
147 TQString m_fullTemplateName;
149
150 bool m_nostartupdlg;
151
152 // the main widget
153 TQWidget *m_mainwidget;
154
155 // do not show this dialog at startup
156 TQCheckBox *m_nodiag;
157
158 // choose a template
159 KJanusWidget * m_jwidget;
160 KFileIconView *m_recent;
161 TQVGroupBox * boxdescription;
162 KTextEdit * textedit;
163
164 // choose a file
165 MyFileDialog *m_filedialog;
166
167 // for the layout
168 TQTabWidget* tabWidget;
169 TQWidget* newTab;
170 TQWidget* existingTab;
171 TQWidget* recentTab;
172
173};
174
175/******************************************************************/
176/* Class: KoTemplateChooseDia */
177/******************************************************************/
178
179/*================================================================*/
180KoTemplateChooseDia::KoTemplateChooseDia(TQWidget *parent, const char *name, TDEInstance* instance,
181 const TQCString &format,
182 const TQString &nativeName,
183 const TQStringList &extraNativeMimeTypes,
184 const DialogType &dialogType,
185 const TQCString& templateType) :
186 KDialogBase(parent, name, true, i18n("Open Document"), KDialogBase::Ok | KDialogBase::Cancel,
187 KDialogBase::Ok)
188{
189 d = new KoTemplateChooseDiaPrivate(
190 templateType,
191 instance,
192 format,
193 nativeName,
194 extraNativeMimeTypes,
195 dialogType);
196
197 TQPushButton* ok = actionButton( KDialogBase::Ok );
198 TQPushButton* cancel = actionButton( KDialogBase::Cancel );
199 cancel->setAutoDefault(false);
200 ok->setDefault(true);
201 //enableButtonOK(false);
202
203 if (!templateType.isNull() && !templateType.isEmpty() && dialogType!=NoTemplates)
204 d->tree = new KoTemplateTree(templateType, instance, true);
205
206 d->m_mainwidget = makeMainWidget();
207
208 d->m_templateName = "";
209 d->m_fullTemplateName = "";
210 d->m_returnType = Cancel;
211
212 setupDialog();
213}
214
215KoTemplateChooseDia::~KoTemplateChooseDia()
216{
217 delete d->tree;
218 delete d;
219 d=0L;
220}
221
222// Keep in sync with KoMainWindow::chooseNewDocument
223static bool cancelQuits() {
224 bool onlyDoc = !KoDocument::documentList() || KoDocument::documentList()->count() <= 1;
225 bool onlyMainWindow = !TDEMainWindow::memberList || TDEMainWindow::memberList->count() <= 1;
226 return onlyDoc && onlyMainWindow && kapp->instanceName() != "koshell"; // hack for koshell
227}
228
230 const KoTemplateChooseDia::DialogType &dialogType,
231 const TQCString& templateType,
232 TQWidget* parent)
233{
234 const TQString nativeName = instance->aboutData()->programName();
235 const TQCString format = KoDocument::readNativeFormatMimeType( instance );
236 const TQStringList extraNativeMimeTypes = KoDocument::readExtraNativeMimeTypes( instance );
237 // Maybe the above two can be combined into one call, for speed:
238 //KoDocument::getNativeMimeTypeInfo( instance, nativeName, extraNativeMimeTypes );
239 return choose( instance, file, format, nativeName, extraNativeMimeTypes,
240 dialogType, templateType, parent );
241}
242
243KoTemplateChooseDia::ReturnType KoTemplateChooseDia::choose(TDEInstance* instance, TQString &file,
244 const TQCString &format,
245 const TQString &nativeName,
246 const TQStringList& extraNativeMimeTypes,
247 const DialogType &dialogType,
248 const TQCString& templateType,
249 TQWidget* parent )
250{
252 parent, "Choose", instance, format,
253 nativeName, extraNativeMimeTypes, dialogType, templateType );
254
256
257 if (dlg->noStartupDlg())
258 {
259 // start with the default template
260 file = dlg->getFullTemplate();
261 rt = dlg->getReturnType();
262 }
263 else
264 {
265 dlg->resize( 700, 480 );
266 if ( dlg->exec() == TQDialog::Accepted )
267 {
268 file = dlg->getFullTemplate();
269 rt = dlg->getReturnType();
270 }
271 }
272
273 delete dlg;
274 return rt;
275}
276
277bool KoTemplateChooseDia::noStartupDlg() const {
278 return d->m_nostartupdlg;
279}
280
281
283 return d->m_templateName;
284}
285
287 return d->m_fullTemplateName;
288}
289
293
297
298/*================================================================*/
299// private
300void KoTemplateChooseDia::setupRecentDialog(TQWidget * widgetbase, TQGridLayout * layout)
301{
302
303 d->m_recent = new KoTCDRecentFilesIconView(widgetbase, "recent files");
304 // I prefer the icons to be in "most recent first" order (DF)
305 d->m_recent->setSorting( static_cast<TQDir::SortSpec>( TQDir::Time | TQDir::Reversed ) );
306 layout->addWidget(d->m_recent,0,0);
307
308 TQString oldGroup = d->m_instance->config()->group();
309 d->m_instance->config()->setGroup( "RecentFiles" );
310
311 int i = 0;
312 TQString value;
313 do {
314 TQString key=TQString( "File%1" ).arg( i );
315 value=d->m_instance->config()->readPathEntry( key );
316 if ( !value.isEmpty() ) {
317 // Support for tdelibs-3.5's new RecentFiles format: name[url]
318 TQString s = value;
319 if ( s.endsWith("]") )
320 {
321 int pos = s.find("[");
322 s = s.mid( pos + 1, s.length() - pos - 2);
323 }
324 KURL url(s);
325
326 if(!url.isLocalFile() || TQFile::exists(url.path())) {
327 KFileItem *item = new KFileItem( KFileItem::Unknown, KFileItem::Unknown, url );
328 d->m_recent->insertItem(item);
329 }
330 }
331 i++;
332 } while ( !value.isEmpty() || i<=10 );
333
334 d->m_instance->config()->setGroup( oldGroup );
335 d->m_recent->showPreviews();
336
337 connect(d->m_recent, TQ_SIGNAL( doubleClicked ( TQIconViewItem * ) ),
338 this, TQ_SLOT( recentSelected( TQIconViewItem * ) ) );
339
340}
341
342/*================================================================*/
343// private
344void KoTemplateChooseDia::setupFileDialog(TQWidget * widgetbase, TQGridLayout * layout)
345{
346 TQString dir = TQString();
347 TQPoint point( 0, 0 );
348
349 d->m_filedialog=new MyFileDialog(dir,
350 TQString(),
351 widgetbase,
352 "file dialog",
353 false);
354
355 layout->addWidget(d->m_filedialog,0,0);
356 d->m_filedialog->reparent( widgetbase , point );
357 //d->m_filedialog->setOperationMode( KFileDialog::Opening);
358
359 TQObjectList *l = d->m_filedialog->queryList( "TQPushButton" );
360 TQObjectListIt childit( *l );
361 TQObject *obj;
362 while ( (obj = childit.current()) != 0 ) {
363 ++childit;
364 ((TQPushButton*)obj)->hide();
365 }
366 delete l;
367
368 d->m_filedialog->setSizeGripEnabled ( false );
369
370 TQStringList mimeFilter = KoFilterManager::mimeFilter( d->m_format, KoFilterManager::Import );
371 TQStringList::Iterator mimeFilterIt = mimeFilter.at( 1 );
372 for ( TQStringList::ConstIterator it = d->m_extraNativeMimeTypes.begin();
373 it != d->m_extraNativeMimeTypes.end(); ++it ) {
374 mimeFilterIt = mimeFilter.insert( mimeFilterIt, *it );
375 ++mimeFilterIt;
376 }
377 d->m_filedialog->setMimeFilter( mimeFilter );
378
379 connect(d->m_filedialog, TQ_SIGNAL( okClicked() ),
380 this, TQ_SLOT ( slotOk() ));
381
382 connect(d->m_filedialog, TQ_SIGNAL( cancelClicked() ),
383 this, TQ_SLOT ( slotCancel() ));
384
385}
386
387/*================================================================*/
388// private
389void KoTemplateChooseDia::setupTemplateDialog(TQWidget * widgetbase, TQGridLayout * layout)
390{
391
392 d->m_jwidget = new KJanusWidget(
393 widgetbase,
394 "kjanuswidget",
396 layout->addWidget(d->m_jwidget,0,0);
397
398 d->boxdescription = new TQVGroupBox(
399 i18n("Selected Template"),
400 widgetbase,
401 "boxdescription");
402 layout->addWidget(d->boxdescription, 1, 0 );
403
404 // config
405 TDEConfigGroup grp( d->m_instance->config(), "TemplateChooserDialog" );
406 int templateNum = grp.readNumEntry( "TemplateTab", -1 );
407 TQString templateName = grp.readPathEntry( "TemplateName" );
408 if ( templateName.isEmpty() && d->tree->defaultTemplate() )
409 templateName = d->tree->defaultTemplate()->name(); //select the default template for the app
410
411 // item which will be selected initially
412 TQIconViewItem * itemtoselect = 0;
413
414 // count the templates inserted
415 int entriesnumber = 0;
416 int defaultTemplateGroup = -1;
417
418 for ( KoTemplateGroup *group = d->tree->first(); group!=0L; group=d->tree->next() )
419 {
420 if (group->isHidden())
421 continue;
422
423 if ( d->tree->defaultGroup() == group )
424 defaultTemplateGroup = entriesnumber; //select the default template group for the app
425
426 TQFrame * frame = d->m_jwidget->addPage (
427 group->name(),
428 group->name(),
429 group->first()->loadPicture(d->m_instance));
430
431 TQGridLayout * layout = new TQGridLayout(frame);
432 KoTCDIconCanvas *canvas = new KoTCDIconCanvas( frame );
433 layout->addWidget(canvas,0,0);
434
435 canvas->setBackgroundColor( colorGroup().base() );
436 canvas->setResizeMode(TQIconView::Adjust);
437 canvas->setWordWrapIconText( true );
438 canvas->show();
439
440 TQIconViewItem * tempitem = canvas->load(group, templateName, d->m_instance);
441 if (tempitem)
442 itemtoselect = tempitem;
443
444 canvas->sort();
445 canvas->setSelectionMode(TQIconView::Single);
446
447 connect( canvas, TQ_SIGNAL( clicked ( TQIconViewItem * ) ),
448 this, TQ_SLOT( currentChanged( TQIconViewItem * ) ) );
449
450 connect( canvas, TQ_SIGNAL( doubleClicked( TQIconViewItem * ) ),
451 this, TQ_SLOT( chosen(TQIconViewItem *) ) );
452
453 entriesnumber++;
454 }
455
456 d->boxdescription->setInsideMargin ( 3 );
457 d->boxdescription->setInsideSpacing ( 3 );
458
459 d->textedit = new KTextEdit( d->boxdescription );
460 d->textedit->setReadOnly(1);
461 d->textedit->setText(descriptionText(i18n("Empty Document"), i18n("Creates an empty document")));
462 d->textedit->setLineWidth(0);
463 d->textedit->setMaximumHeight(50);
464
465 // Hide the widget if there is no template available. This should never happen ;-)
466 if (!entriesnumber)
467 d->m_jwidget->hide();
468
469 // Set the initially shown page, possibly from the last usage of the dialog
470 if (entriesnumber >= templateNum && templateNum != -1 )
471 d->m_jwidget->showPage(templateNum);
472 else if ( defaultTemplateGroup != -1)
473 d->m_jwidget->showPage(defaultTemplateGroup);
474
475
476 // Set the initially selected template, possibly from the last usage of the dialog
477 currentChanged(itemtoselect);
478
479 // setup the checkbox
480 TQString translatedstring = i18n("Always start %1 with the selected template").arg(d->m_nativeName);
481
482 d->m_nodiag = new TQCheckBox ( translatedstring , widgetbase);
483 layout->addWidget(d->m_nodiag, 2, 0);
484 TQString startwithoutdialog = grp.readEntry( "NoStartDlg" );
485 bool ischecked = startwithoutdialog == TQString("yes");
486
487 // When not starting up, display a tri-state button telling whether
488 // the user actually choosed the template to start with next times (bug:77542)
489 if (d->m_dialogType == Everything)
490 {
491 d->m_nodiag->setChecked( ischecked );
492 }
493 else
494 {
495 d->m_nodiag->setTristate();
496 d->m_nodiag->setNoChange();
497 }
498}
499
500/*================================================================*/
501// private
502void KoTemplateChooseDia::setupDialog()
503{
504
505 TQGridLayout *maingrid=new TQGridLayout( d->m_mainwidget, 1, 1, 2, 6);
506 TDEConfigGroup grp( d->m_instance->config(), "TemplateChooserDialog" );
507
508 if (d->m_dialogType == Everything)
509 {
510
511 // the user may want to start with his favorite template
512 if (grp.readEntry( "NoStartDlg" ) == TQString("yes") )
513 {
514 d->m_nostartupdlg = true;
515 d->m_returnType = Empty;
516
517 // no default template, just start with an empty document
518 if (grp.readEntry("LastReturnType") == TQString("Empty") )
519 return;
520
521 // start with the default template
522 d->m_templateName = grp.readPathEntry( "TemplateName" );
523 d->m_fullTemplateName = grp.readPathEntry( "FullTemplateName" );
524
525 // be paranoid : invalid template means empty template
526 if (!TQFile::exists(d->m_fullTemplateName))
527 return;
528
529 if (d->m_fullTemplateName.length() < 2)
530 return;
531
532 d->m_returnType = Template;
533 return;
534 }
535
536 if ( cancelQuits() )
537 setButtonCancel( KStdGuiItem::quit() );
538
539 d->tabWidget = new TQTabWidget( d->m_mainwidget, "tabWidget" );
540 maingrid->addWidget( d->tabWidget, 0, 0 );
541
542 // new document
543 d->newTab = new TQWidget( d->tabWidget, "newTab" );
544 d->tabWidget->insertTab( d->newTab, i18n( "&Create Document" ) );
545 TQGridLayout * newTabLayout = new TQGridLayout( d->newTab, 1, 1, KDialogBase::marginHint(), KDialogBase::spacingHint());
546
547 // existing document
548 d->existingTab = new TQWidget( d->tabWidget, "existingTab" );
549 d->tabWidget->insertTab( d->existingTab, i18n( "Open &Existing Document" ) );
550 TQGridLayout * existingTabLayout = new TQGridLayout( d->existingTab, 1, 1, 0, KDialog::spacingHint());
551
552 // recent document
553 d->recentTab = new TQWidget( d->tabWidget, "recentTab" );
554 d->tabWidget->insertTab( d->recentTab, i18n( "Open &Recent Document" ) );
555 TQGridLayout * recentTabLayout = new TQGridLayout( d->recentTab, 1, 1, KDialogBase::marginHint(), KDialog::spacingHint());
556
557 setupTemplateDialog(d->newTab, newTabLayout);
558 setupFileDialog(d->existingTab, existingTabLayout);
559 setupRecentDialog(d->recentTab, recentTabLayout);
560
561 TQString tabhighlighted = grp.readEntry("LastReturnType");
562 if ( tabhighlighted == "Template" )
563 d->tabWidget->setCurrentPage(0); // CreateDocument tab
564 else if (tabhighlighted == "File" )
565 d->tabWidget->setCurrentPage(2); // RecentDocument tab
566 else
567 d->tabWidget->setCurrentPage(0); // Default setting: CreateDocument tab
568 }
569 else
570 {
571
572 // open a file
573 if (d->m_dialogType == NoTemplates)
574 {
575 setupFileDialog(d->m_mainwidget, maingrid);
576 }
577 // create a new document from a template
578 if (d->m_dialogType == OnlyTemplates)
579 {
580 setCaption(i18n( "Create Document" ));
581 setupTemplateDialog(d->m_mainwidget, maingrid);
582 }
583 }
584}
585
586/*================================================================*/
587// private SLOT
588void KoTemplateChooseDia::currentChanged( TQIconViewItem * item)
589{
590 if (item)
591 {
592 TQIconView* canvas = item->iconView();
593
594 // set text in the textarea
595 d->textedit->setText( descriptionText(
596 item->text(),
597 ((KoTCDIconViewItem *) item)->getDescr()
598 ));
599
600 // set the icon in the canvas selected
601 if (canvas)
602 canvas->setSelected(item,1,0);
603
604 // register the current template
605 d->m_templateName = item->text();
606 d->m_fullTemplateName = ((KoTCDIconViewItem *) item)->getFName();
607 }
608}
609
610/*================================================================*/
611// private SLOT
612void KoTemplateChooseDia::chosen(TQIconViewItem * item)
613{
614 // the user double clicked on a template
615 if (item)
616 {
617 currentChanged(item);
618 slotOk();
619 }
620}
621
622/* */
623// private SLOT
624void KoTemplateChooseDia::recentSelected( TQIconViewItem * item)
625{
626 if (item)
627 {
628 slotOk();
629 }
630}
631
632/*================================================================*/
633// protected SLOT
635{
636 // Collect info from the dialog into d->m_returnType and d->m_templateName etc.
637 if (collectInfo())
638 {
639 // Save it for the next time
640 TDEConfigGroup grp( d->m_instance->config(), "TemplateChooserDialog" );
641 static const char* const s_returnTypes[] = { 0 /*Cancel ;)*/, "Template", "File", "Empty" };
642 if ( d->m_returnType <= Empty )
643 {
644 grp.writeEntry( "LastReturnType", TQString::fromLatin1(s_returnTypes[d->m_returnType]) );
645 if (d->m_returnType == Template)
646 {
647 grp.writeEntry( "TemplateTab", d->m_jwidget->activePageIndex() );
648 grp.writePathEntry( "TemplateName", d->m_templateName );
649 grp.writePathEntry( "FullTemplateName", d->m_fullTemplateName);
650 }
651
652 if (d->m_nodiag)
653 {
654 // The checkbox m_nodiag is in tri-state mode for new documents
655 // fixes bug:77542
656 if (d->m_nodiag->state() == TQButton::On) {
657 grp.writeEntry( "NoStartDlg", "yes");
658 }
659 else if (d->m_nodiag->state() == TQButton::Off) {
660 grp.writeEntry( "NoStartDlg", "no");
661 }
662 }
663 }
664 else
665 {
666 kdWarning(30003) << "Unsupported template chooser result: " << d->m_returnType << endl;
667 grp.writeEntry( "LastReturnType", TQString() );
668 }
670 }
671}
672
673/*================================================================*/
674// private
675bool KoTemplateChooseDia::collectInfo()
676{
677
678
679 // to determine what tab is selected in "Everything" mode
680 bool newTabSelected = false;
681 if ( d->m_dialogType == Everything)
682 if ( d->tabWidget->currentPage() == d->newTab )
683 newTabSelected = true;
684
685 // is it a template or a file ?
686 if ( d->m_dialogType==OnlyTemplates || newTabSelected )
687 {
688 // a template is chosen
689 if (d->m_templateName.length() > 0)
690 d->m_returnType = Template;
691 else
692 d->m_returnType=Empty;
693
694 return true;
695 }
696 else if ( d->m_dialogType != OnlyTemplates )
697 {
698 // a file is chosen
699 if (d->m_dialogType == Everything && d->tabWidget->currentPage() == d->recentTab)
700 {
701 // Recent file
702 KFileItem * item = d->m_recent->currentFileItem();
703 if (! item)
704 return false;
705 KURL url = item->url();
706 if(url.isLocalFile() && !TQFile::exists(url.path()))
707 {
708 KMessageBox::error( this, i18n( "The file %1 does not exist." ).arg( url.path() ) );
709 return false;
710 }
711 d->m_fullTemplateName = url.url();
712 d->m_returnType = File;
713 }
714 else
715 {
716 // Existing file from file dialog
717 if ( !d->m_filedialog->slotOkCalled() )
718 d->m_filedialog->slotOk();
719 KURL url = d->m_filedialog->currentURL();
720 d->m_fullTemplateName = url.url();
721 d->m_returnType = File;
722 return d->m_filedialog->checkURL();
723 }
724 return true;
725 }
726
727 d->m_returnType=Empty;
728 return false;
729}
730
731/*================================================================*/
732//private
733TQString KoTemplateChooseDia::descriptionText(const TQString &name, const TQString &description)
734{
735 TQString descrText(i18n("Name:"));
736 descrText += " " + name;
737 descrText += "\n";
738 descrText += i18n("Description:");
739 if (description.isEmpty())
740 descrText += " " + i18n("No description available");
741 else
742 descrText += " " + description;
743 return descrText;
744}
745
746/*================================================================*/
747
748TQIconViewItem * KoTCDIconCanvas::load( KoTemplateGroup *group, const TQString& name, TDEInstance* instance )
749{
750 TQIconViewItem * itemtoreturn = 0;
751
752 for (KoTemplate *t=group->first(); t!=0L; t=group->next()) {
753 if (t->isHidden())
754 continue;
755 TQIconViewItem *item = new KoTCDIconViewItem(
756 this,
757 t->name(),
758 t->loadPicture(instance),
759 t->description(),
760 t->file());
761
762 if (name == t->name())
763 {
764 itemtoreturn = item;
765 }
766
767 item->setKey(t->name());
768 item->setDragEnabled(false);
769 item->setDropEnabled(false);
770 }
771
772 return itemtoreturn;
773}
774
775/*================================================================*/
776
777KoTCDRecentFilesIconView::~KoTCDRecentFilesIconView()
778{
779 removeToolTip();
780}
781
782void KoTCDRecentFilesIconView::showToolTip( TQIconViewItem* item )
783{
784 removeToolTip();
785 if ( !item )
786 return;
787
788 // Mostly duplicated from KFileIconView, because it only shows tooltips
789 // for truncated icon texts, and we want tooltips on all icons,
790 // with the full path...
791 // KFileIconView would need a virtual method for deciding if a tooltip should be shown,
792 // and another one for deciding what's the text of the tooltip...
793 const KFileItem *fi = ( (KFileIconViewItem*)item )->fileInfo();
794 TQString toolTipText = fi->url().prettyURL( 0, KURL::StripFileProtocol );
795 toolTip = new TQLabel( TQString::fromLatin1(" %1 ").arg(toolTipText), 0,
796 "myToolTip",
797 WStyle_StaysOnTop | WStyle_Customize | WStyle_NoBorder | WStyle_Tool | WX11BypassWM );
798 toolTip->setFrameStyle( TQFrame::Plain | TQFrame::Box );
799 toolTip->setLineWidth( 1 );
800 toolTip->setAlignment( AlignLeft | AlignTop );
801 toolTip->move( TQCursor::pos() + TQPoint( 14, 14 ) );
802 toolTip->adjustSize();
803 TQRect screen = TQApplication::desktop()->screenGeometry(
804 TQApplication::desktop()->screenNumber(TQCursor::pos()));
805 if (toolTip->x()+toolTip->width() > screen.right()) {
806 toolTip->move(toolTip->x()+screen.right()-toolTip->x()-toolTip->width(), toolTip->y());
807 }
808 if (toolTip->y()+toolTip->height() > screen.bottom()) {
809 toolTip->move(toolTip->x(), screen.bottom()-toolTip->y()-toolTip->height()+toolTip->y());
810 }
811 toolTip->setFont( TQToolTip::font() );
812 toolTip->setPalette( TQToolTip::palette(), true );
813 toolTip->show();
814}
815
816void KoTCDRecentFilesIconView::removeToolTip()
817{
818 delete toolTip;
819 toolTip = 0;
820}
821
823{
824 removeToolTip();
825 KFileIconView::hideEvent( ev );
826}
827
828#include "KoTemplateChooseDia.moc"
virtual void slotCancel()
void setButtonCancel(const KGuiItem &item=KStdGuiItem::cancel())
void cancelClicked()
void okClicked()
virtual void slotOk()
static int marginHint()
static int spacingHint()
virtual void setCaption(const TQString &caption)
static void error(TQWidget *parent, const TQString &text, const TQString &caption=TQString::null, int options=Notify)
static TQCString readNativeFormatMimeType(TDEInstance *instance=0)
Used by KoApplication, and by KoMainWindow, when no document exists yet.
static TQStringList readExtraNativeMimeTypes(TDEInstance *instance=0)
Used by KoMainWindow, when no document exists yet.
static TQPtrList< KoDocument > * documentList()
Definition KoDocument.h:712
static TQStringList mimeFilter()
The same method as KoFilterManager::mimeFilter but suited for KoShell.
Our reimplementation of KFileIconView used as the "recent files" view within the template-chooser dia...
virtual void hideEvent(TQHideEvent *)
Reimplemented to remove an eventual tooltip.
This class is used to show the template dialog on startup.
virtual void slotOk()
Activated when the Ok button has been clicked.
ReturnType
The Dialog returns one of these values depending on the input of the user.
static ReturnType choose(TDEInstance *instance, TQString &file, const DialogType &dialogType, const TQCString &templateType, TQWidget *parent)
This is the static method you'll normally use to show the dialog.
DialogType
To configure the dialog you have to use this enum.
TQString getFullTemplate() const
Method to get the "full" template (path+template).
ReturnType getReturnType() const
The ReturnType (call this one after exec()).
DialogType getDialogType() const
The dialogType - normally you won't need this one.
TQString getTemplate() const
Method to get the current template.
static TQPtrList< TDEMainWindow > * memberList
const char * name(StdAction id)