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