kexi

KexiStartupDialogTemplatesPage.cpp
1/* This file is part of the KDE project
2 Copyright (C) 2003-2007 Jaroslaw Staniek <js@iidea.pl>
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, or (at your option) any later version.
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 "KexiStartupDialogTemplatesPage.h"
21
22#include <core/kexi.h>
23#include <core/kexitemplateloader.h>
24#include "KexiProjectSelector.h"
25#include "KexiOpenExistingFile.h"
26#include "KexiConnSelector.h"
27#include "KexiConnSelectorBase.h"
28
29#include <tqheader.h>
30
31#include <kdebug.h>
32#include <kiconloader.h>
33
34#ifdef KEXI_SHOW_UNIMPLEMENTED
35#define KEXI_STARTUP_SHOW_TEMPLATES
36#define KEXI_STARTUP_SHOW_RECENT
37#endif
38
39/*TQPixmap createIcon()
40{
41
42}*/
43
44/*TQString createText(const TQString& name, const TQString& description)
45{
46 TQString txt = "<H2>" + name + "</H2>";
47 if (description.isEmpty())
48 return name + description
49}*/
50
52class TemplateItem : public TDEListViewItem
53{
54 public:
55 TemplateItem(TQListView* parent, const TQString& aFilename,
56 const TQString& name, const TQString& description, const TQPixmap& icon,
57 const TQValueList<KexiProjectData::ObjectInfo>& aAutoopenObjects)
58 : TDEListViewItem(parent, name + "\n" + description)
59 , autoopenObjects(aAutoopenObjects)
60 , filename(aFilename)
61 {
62 setPixmap(0, icon);
63 }
64 ~TemplateItem() {}
65
66 TQValueList<KexiProjectData::ObjectInfo> autoopenObjects;
67 TQString filename;
68};
69
70//-----------------------
71
72KexiStartupDialogTemplatesPage::KexiStartupDialogTemplatesPage( TQWidget * parent )
73 : TDEListView(parent, "KexiStartupDialogTemplatesPage")
74 , m_popuplated(false)
75{
76 addColumn(TQString());
77 header()->hide();
78 setColumnWidthMode(0, Maximum);
79 setResizeMode(LastColumn);
80 setItemMargin(6);
81 connect(this,TQ_SIGNAL(executed(TQListViewItem*)), this, TQ_SLOT(slotExecuted(TQListViewItem*)));
82}
83
84KexiStartupDialogTemplatesPage::~KexiStartupDialogTemplatesPage()
85{
86}
87
88void KexiStartupDialogTemplatesPage::populate()
89{
90 if (m_popuplated)
91 return;
92 m_popuplated = true;
93 KexiTemplateInfo::List list = KexiTemplateLoader::loadListInfo();
94 foreach( TQValueList<KexiTemplateInfo>::ConstIterator, it, list ) {
95 new TemplateItem(this, (*it).filename, (*it).name,
96 (*it).description, (*it).icon, (*it).autoopenObjects);
97 }
98 if (firstChild())
99 setSelected(firstChild(), true);
100
101// templates = new TDEIconView(this, "templates");
102// templates->setItemsMovable(false);
103// templates->setShowToolTips(false);
104// info = new KTextBrowser(this,"info");
105// setResizeMode(templates,KeepSize);
106// setResizeMode(info,KeepSize);
107// connect(templates,TQ_SIGNAL(selectionChanged(TQIconViewItem*)),this,TQ_SLOT(itemClicked(TQIconViewItem*)));
108}
109
110/*
111void TemplatesPage::addItem(const TQString& key, const TQString& name,
112 const TQString& description, const TQPixmap& icon)
113{
114 TemplateItem *item = new TemplateItem(templates, name, icon);
115 item->key=key;
116 item->name=name;
117 item->description=description;
118}
119
120void TemplatesPage::itemClicked(TQIconViewItem *item) {
121 if (!item) {
122 info->setText("");
123 return;
124 }
125 TQString t = TQString("<h2>%1</h2><p>%2</p>")
126 .arg(static_cast<TemplateItem*>(item)->name)
127 .arg(static_cast<TemplateItem*>(item)->description);
128#ifndef DB_TEMPLATES
129 t += TQString("<p>") + i18n("We are sorry, templates are not yet available.") +"</p>";
130#endif
131
132 info->setText( t );
133}*/
134
135TQString KexiStartupDialogTemplatesPage::selectedFileName() const
136{
137 TemplateItem* templateItem = static_cast<TemplateItem*>(selectedItem());
138 return templateItem ? templateItem->filename : TQString();
139}
140
141TQValueList<KexiProjectData::ObjectInfo>
142KexiStartupDialogTemplatesPage::autoopenObjectsForSelectedTemplate() const
143{
144 TemplateItem* templateItem = static_cast<TemplateItem*>(selectedItem());
145 return templateItem ? templateItem->autoopenObjects : TQValueList<KexiProjectData::ObjectInfo>();
146}
147
148void KexiStartupDialogTemplatesPage::slotExecuted(TQListViewItem* item)
149{
150 TemplateItem* templateItem = static_cast<TemplateItem*>(item);
151 if (!templateItem)
152 return;
153
154 emit selected(templateItem->filename);
155}
156
157#include "KexiStartupDialogTemplatesPage.moc"