kexi

KexiStartupDialogTemplatesPage.cpp

00001 /* This file is part of the KDE project
00002    Copyright (C) 2003-2007 Jaroslaw Staniek <js@iidea.pl>
00003 
00004    This library is free software; you can redistribute it and/or
00005    modify it under the terms of the GNU Library General Public
00006    License as published by the Free Software Foundation; either
00007    version 2 of the License, or (at your option) any later version.
00008 
00009    This library is distributed in the hope that it will be useful,
00010    but WITHOUT ANY WARRANTY; without even the implied warranty of
00011    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00012    Library General Public License for more details.
00013 
00014    You should have received a copy of the GNU Library General Public License
00015    along with this library; see the file COPYING.LIB.  If not, write to
00016    the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
00017  * Boston, MA 02110-1301, USA.
00018   */
00019 
00020 #include "KexiStartupDialogTemplatesPage.h"
00021 
00022 #include <core/kexi.h>
00023 #include <core/kexitemplateloader.h>
00024 #include "KexiProjectSelector.h"
00025 #include "KexiOpenExistingFile.h"
00026 #include "KexiConnSelector.h"
00027 #include "KexiConnSelectorBase.h"
00028 
00029 #include <qheader.h>
00030 
00031 #include <kdebug.h>
00032 #include <kiconloader.h>
00033 
00034 #ifdef KEXI_SHOW_UNIMPLEMENTED
00035 #define KEXI_STARTUP_SHOW_TEMPLATES
00036 #define KEXI_STARTUP_SHOW_RECENT
00037 #endif
00038 
00039 /*QPixmap createIcon()
00040 {
00041     
00042 }*/
00043 
00044 /*QString createText(const QString& name, const QString& description)
00045 {
00046     QString txt = "<H2>" + name + "</H2>";
00047     if (description.isEmpty())
00048     return name + description
00049 }*/
00050 
00052 class TemplateItem : public KListViewItem
00053 {
00054     public:
00055         TemplateItem(QListView* parent, const QString& aFilename, 
00056             const QString& name, const QString& description, const QPixmap& icon, 
00057             const QValueList<KexiProjectData::ObjectInfo>& aAutoopenObjects)
00058         : KListViewItem(parent, name + "\n" + description)
00059         , autoopenObjects(aAutoopenObjects)
00060         , filename(aFilename)
00061         {
00062             setPixmap(0, icon);
00063         }
00064         ~TemplateItem() {}
00065 
00066     QValueList<KexiProjectData::ObjectInfo> autoopenObjects;
00067     QString filename;
00068 };
00069 
00070 //-----------------------
00071 
00072 KexiStartupDialogTemplatesPage::KexiStartupDialogTemplatesPage( QWidget * parent )
00073     : KListView(parent, "KexiStartupDialogTemplatesPage")
00074     , m_popuplated(false)
00075 {
00076     addColumn(QString::null);
00077     header()->hide();
00078     setColumnWidthMode(0, Maximum);
00079     setResizeMode(LastColumn);
00080     setItemMargin(6);
00081     connect(this,SIGNAL(executed(QListViewItem*)), this, SLOT(slotExecuted(QListViewItem*)));
00082 }
00083 
00084 KexiStartupDialogTemplatesPage::~KexiStartupDialogTemplatesPage()
00085 {
00086 }
00087 
00088 void KexiStartupDialogTemplatesPage::populate()
00089 {
00090     if (m_popuplated)
00091         return;
00092     m_popuplated = true;
00093     KexiTemplateInfo::List list = KexiTemplateLoader::loadListInfo();
00094     foreach( QValueList<KexiTemplateInfo>::ConstIterator, it, list ) {
00095         new TemplateItem(this, (*it).filename, (*it).name, 
00096             (*it).description, (*it).icon, (*it).autoopenObjects);
00097     }
00098     if (firstChild())
00099         setSelected(firstChild(), true);
00100 
00101 //  templates = new KIconView(this, "templates");
00102 //  templates->setItemsMovable(false);
00103 //  templates->setShowToolTips(false);
00104 //  info = new KTextBrowser(this,"info");
00105 //  setResizeMode(templates,KeepSize);
00106 //  setResizeMode(info,KeepSize);
00107 //  connect(templates,SIGNAL(selectionChanged(QIconViewItem*)),this,SLOT(itemClicked(QIconViewItem*)));
00108 }
00109 
00110 /*
00111 void TemplatesPage::addItem(const QString& key, const QString& name,
00112     const QString& description, const QPixmap& icon)
00113 {
00114     TemplateItem *item = new TemplateItem(templates, name, icon);
00115     item->key=key;
00116     item->name=name;
00117     item->description=description;
00118 }
00119 
00120 void TemplatesPage::itemClicked(QIconViewItem *item) {
00121     if (!item) {
00122         info->setText("");
00123         return;
00124     }
00125     QString t = QString("<h2>%1</h2><p>%2</p>")
00126         .arg(static_cast<TemplateItem*>(item)->name)
00127         .arg(static_cast<TemplateItem*>(item)->description);
00128 #ifndef DB_TEMPLATES
00129     t += QString("<p>") + i18n("We are sorry, templates are not yet available.") +"</p>";
00130 #endif
00131 
00132     info->setText( t );
00133 }*/
00134 
00135 QString KexiStartupDialogTemplatesPage::selectedFileName() const
00136 {
00137     TemplateItem* templateItem = static_cast<TemplateItem*>(selectedItem());
00138     return templateItem ? templateItem->filename : QString::null;
00139 }
00140 
00141 QValueList<KexiProjectData::ObjectInfo>
00142 KexiStartupDialogTemplatesPage::autoopenObjectsForSelectedTemplate() const
00143 {
00144     TemplateItem* templateItem = static_cast<TemplateItem*>(selectedItem());
00145     return templateItem ? templateItem->autoopenObjects : QValueList<KexiProjectData::ObjectInfo>();
00146 }
00147 
00148 void KexiStartupDialogTemplatesPage::slotExecuted(QListViewItem* item)
00149 {
00150     TemplateItem* templateItem = static_cast<TemplateItem*>(item);
00151     if (!templateItem)
00152         return;
00153 
00154     emit selected(templateItem->filename);
00155 }
00156 
00157 #include "KexiStartupDialogTemplatesPage.moc"
KDE Home | KDE Accessibility Home | Description of Access Keys