kexiappmainwindow.cpp
1/***************************************************************************
2 * kexiappmainwindow.cpp
3 * This file is part of the KDE project
4 * copyright (C)2004-2005 by Sebastian Sauer (mail@dipe.org)
5 *
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Library General Public
8 * License as published by the Free Software Foundation; either
9 * version 2 of the License, or (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Library General Public License for more details.
14 * You should have received a copy of the GNU Library General Public License
15 * along with this program; see the file COPYING. 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 "kexiappmainwindow.h"
21#include "kexiapppart.h"
22
23#include "core/keximainwindow.h"
24#include "core/kexiproject.h"
25#include "core/kexi.h"
26#include "kexidb/connection.h"
27
28#include "main/manager.h"
29
30//#include <kdebug.h>
31
32namespace Kross { namespace KexiApp {
33
35 class KexiAppMainWindowPrivate
36 {
37 public:
38 KexiMainWindow* mainwindow;
39
40 KexiProject* project() {
41 KexiProject* project = mainwindow->project();
42 if(! project)
43 throw Kross::Api::Exception::Ptr( new Kross::Api::Exception("No project loaded.") );
44 return project;
45 }
46 };
47
48}}
49
50using namespace Kross::KexiApp;
51
53 : Kross::Api::Class<KexiAppMainWindow>("KexiAppMainWindow")
54 , d(new KexiAppMainWindowPrivate())
55{
56 d->mainwindow = mainwindow;
57
58 this->addFunction0<Kross::Api::Variant>("isConnected", this, &KexiAppMainWindow::isConnected);
59 this->addFunction0<Kross::Api::Object>("getConnection", this, &KexiAppMainWindow::getConnection);
60
61 this->addFunction1<Kross::Api::List, Kross::Api::Variant>("getPartItems", this, &KexiAppMainWindow::getPartItems);
62 this->addFunction1<Kross::Api::Variant, KexiAppPartItem>("openPartItem", this, &KexiAppMainWindow::openPartItem);
63}
64
69
70const TQString KexiAppMainWindow::getClassName() const
71{
72 return "Kross::KexiApp::KexiAppMainWindow";
73}
74
76{
77 return d->project()->isConnected();
78}
79
80Kross::Api::Object::Ptr KexiAppMainWindow::getConnection()
81{
82 ::KexiDB::Connection* connection = d->project()->dbConnection();
83 if(! connection)
84 throw Kross::Api::Exception::Ptr( new Kross::Api::Exception("No connection established.") );
85 Kross::Api::Module::Ptr module = Kross::Api::Manager::scriptManager()->loadModule("krosskexidb");
86 if(! module)
87 throw Kross::Api::Exception::Ptr( new Kross::Api::Exception("Could not load \"krosskexidb\" module.") );
88 return module->get("KexiDBConnection", connection);
89}
90
91Kross::Api::List* KexiAppMainWindow::getPartItems(const TQString& mimetype)
92{
93 if(mimetype.isNull()) return 0; // just to be sure...
94 KexiPart::ItemDict* items = d->project()->itemsForMimeType( mimetype.latin1() );
95 if(! items) return 0;
96 return new Kross::Api::ListT<KexiAppPartItem>( *items );
97}
98
100{
101 bool openingCancelled;
102 KexiDialogBase* dialog = partitem
103 ? d->mainwindow->openObject(partitem->item(), Kexi::DataViewMode, openingCancelled)
104 : 0;
105 return (dialog != 0 && ! openingCancelled);
106}
Provides database connection, allowing queries and data modification.
Definition connection.h:62
Base class for child window of Kexi's main application window.
Kexi's main window interface This interface is implemented by KexiMainWindowImpl class.
virtual KexiProject * project()=0
Project data of currently opened project or NULL if no project here yet.
A project's main controller.
Definition kexiproject.h:68
Class to handle Kexi's mainwindow instance.
Kross::Api::Object::Ptr getConnection()
Kross::Api::List * getPartItems(const TQString &mimetype)
KexiAppMainWindow(KexiMainWindow *mainwindow)
Constructor.
virtual const TQString getClassName() const
bool openPartItem(KexiAppPartItem *partitem)
Try to open the defined KexiAppPartItem and.
Class to handle Kexi Part::Item instance.
Definition kexiapppart.h:42
Wrapper around the Kexi-application to access runtime information a running Kexi-application likes to...