kexi

kexiuseraction.cpp
1#include <tdemessagebox.h>
2#include <kdebug.h>
3#include <tdeshortcut.h>
4
5#include <kexidb/cursor.h>
6
7#include "kexipart.h"
8#include "kexipartmanager.h"
9
10#include "kexiproject.h"
11#include "keximainwindow.h"
12#include "kexiuseraction.h"
13
14KexiUserAction::KexiUserAction(KexiMainWindow *win, TDEActionCollection *parent, const TQString &name, const TQString &text, const TQString &pixmap)
15 : TDEAction(text, pixmap, TDEShortcut::null(), this, TQ_SLOT(execute()), parent, name.latin1())
16{
17 m_win = win;
18 m_method = 0;
19 connect(this, TQ_SIGNAL(activated()), this, TQ_SLOT(execute()));
20}
21
22void
23KexiUserAction::setMethod(int method, Arguments args)
24{
25 m_method = method;
26 m_args = args;
27}
28
29void
31{
32 kdDebug() << "KexiUserAction::execute(): " << KexiUserActionMethod::methodName(m_method) << endl;
33
34 switch(m_method)
35 {
36 case OpenObject: //open a project object
37 {
38 //get partinfo
39 KexiPart::Info *i = Kexi::partManager().infoForMimeType(m_args[0].toString().latin1());
40 if (!i) {
41 KMessageBox::error(m_win, i18n("Specified part does not exist"));
42 return;
43 }
44
45 Kexi::partManager().part(i); //load part if doesn't exists
46 KexiPart::Item *item = m_win->project()->item(i, m_args[1].toString());
47 bool openingCancelled;
48 if(!m_win->openObject(item, Kexi::DataViewMode, openingCancelled) && !openingCancelled) {
49 KMessageBox::error(m_win, i18n("Specified document could not be opened."));
50 return;
51 }
52 if (openingCancelled)
53 return;
54 break;
55 }
56 default:
57 break;
58 }
59}
60
62KexiUserAction::fromCurrentRecord(KexiMainWindow *context, TDEActionCollection *parent, KexiDB::Cursor *c)
63{
64 if(!c || c->bof() || c->eof())
65 return 0;
66
67 KexiUserAction *a = new KexiUserAction(context, parent, c->value(1).toString(), c->value(2).toString(), c->value(3).toString());
68 TQString args = c->value(5).toString();
69 bool quote = false;
70
71 Arguments arg;
72 TQString tmp;
73 const int len = args.length();
74 for(int i=0; i < len; i++)
75 {
76 if(args[i] == '"') // if current char is quoted unqote or other way round
77 {
78 quote = !quote;
79 }
80 else if(args[i] == ',' && !quote) //if item end add tmp to argumentstack and strip quotes if nessesery
81 {
82 if(tmp.left(1)=="\"" && tmp.right(1)=="\"")
83 tmp = tmp.mid(1, tmp.length()-2);
84
85 arg.append(TQVariant(tmp));
86 tmp = "";
87 }
88 else //else simply add char to tmp
89 {
90 tmp += args[i];
91 }
92 }
93
94 if(tmp.left(1)=="\"" && tmp.right(1)=="\"")
95 tmp = tmp.mid(1, tmp.length()-2);
96
97 arg.append(TQVariant(tmp));
98
99 a->setMethod(c->value(4).toInt(), arg);
100 return a;
101}
102
103KexiUserAction::~KexiUserAction()
104{
105}
106
107#include "kexiuseraction.moc"
108
Provides database cursor functionality.
Definition cursor.h:67
virtual TQVariant value(uint i)=0
bool bof() const
Definition cursor.cpp:344
bool eof() const
Definition cursor.cpp:339
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.
virtual KexiDialogBase * openObject(KexiPart::Item *item, int viewMode, bool &openingCancelled, TQMap< TQString, TQString > *staticObjectArgs=0, TQString *errorMessage=0)=0
Opens object pointed by item in a view viewMode.
Information about a Kexi Part (plugin).
Information about a single object that can be instantiated using Kexi Part.
Info * infoForMimeType(const TQString &mimeType)
KexiPart::Item * item(KexiPart::Info *i, const TQString &name)
static TQString methodName(int method)
KexiUserAction(KexiMainWindow *context, TDEActionCollection *parent, const TQString &name, const TQString &text, const TQString &pixmap)
static KexiUserAction * fromCurrentRecord(KexiMainWindow *context, TDEActionCollection *parent, KexiDB::Cursor *c)
void setMethod(int method, Arguments args)
KEXICORE_EXPORT KexiPart::Manager & partManager()
shared part manager
Definition kexi.cpp:97