kexi

kexiuseraction.cpp

00001 #include <kmessagebox.h>
00002 #include <kdebug.h>
00003 #include <kshortcut.h>
00004 
00005 #include <kexidb/cursor.h>
00006 
00007 #include "kexipart.h"
00008 #include "kexipartmanager.h"
00009 
00010 #include "kexiproject.h"
00011 #include "keximainwindow.h"
00012 #include "kexiuseraction.h"
00013 
00014 KexiUserAction::KexiUserAction(KexiMainWindow *win, KActionCollection *parent, const QString &name, const QString &text, const QString &pixmap)
00015  : KAction(text, pixmap, KShortcut::null(), this, SLOT(execute()), parent, name.latin1())
00016 {
00017     m_win = win;
00018     m_method = 0;
00019     connect(this, SIGNAL(activated()), this, SLOT(execute()));
00020 }
00021 
00022 void
00023 KexiUserAction::setMethod(int method, Arguments args)
00024 {
00025     m_method = method;
00026     m_args = args;
00027 }
00028 
00029 void
00030 KexiUserAction::execute()
00031 {
00032     kdDebug() << "KexiUserAction::execute(): " << KexiUserActionMethod::methodName(m_method) << endl;
00033 
00034     switch(m_method)
00035     {
00036         case OpenObject: //open a project object
00037         {
00038             //get partinfo
00039             KexiPart::Info *i = Kexi::partManager().infoForMimeType(m_args[0].toString().latin1());
00040             if (!i) {
00041                 KMessageBox::error(m_win, i18n("Specified part does not exist"));
00042                 return;
00043             }
00044 
00045             Kexi::partManager().part(i); //load part if doesn't exists
00046             KexiPart::Item *item = m_win->project()->item(i, m_args[1].toString());
00047             bool openingCancelled;
00048             if(!m_win->openObject(item, Kexi::DataViewMode, openingCancelled) && !openingCancelled) {
00049                 KMessageBox::error(m_win, i18n("Specified document could not be opened."));
00050                 return;
00051             }
00052             if (openingCancelled)
00053                 return;
00054             break;
00055         }   
00056         default:
00057             break;
00058     }
00059 }
00060 
00061 KexiUserAction *
00062 KexiUserAction::fromCurrentRecord(KexiMainWindow *context, KActionCollection *parent, KexiDB::Cursor *c)
00063 {
00064     if(!c || c->bof() || c->eof())
00065         return 0;
00066 
00067     KexiUserAction *a = new KexiUserAction(context, parent, c->value(1).toString(), c->value(2).toString(), c->value(3).toString());
00068     QString args = c->value(5).toString();
00069     bool quote = false;
00070 
00071     Arguments arg;
00072     QString tmp;
00073     const int len = args.length();
00074     for(int i=0; i < len; i++)
00075     {
00076         if(args[i] == '"') // if current char is quoted unqote or other way round
00077         {
00078             quote = !quote;
00079         }
00080         else if(args[i] == ',' && !quote) //if item end add tmp to argumentstack and strip quotes if nessesery
00081         {
00082             if(tmp.left(1)=="\"" && tmp.right(1)=="\"")
00083                 tmp = tmp.mid(1, tmp.length()-2);
00084 
00085             arg.append(QVariant(tmp));
00086             tmp = "";
00087         }
00088         else //else simply add char to tmp
00089         {
00090             tmp += args[i];
00091         }
00092     }
00093 
00094     if(tmp.left(1)=="\"" && tmp.right(1)=="\"")
00095         tmp = tmp.mid(1, tmp.length()-2);
00096 
00097     arg.append(QVariant(tmp));
00098 
00099     a->setMethod(c->value(4).toInt(), arg);
00100     return a;
00101 }
00102 
00103 KexiUserAction::~KexiUserAction()
00104 {
00105 }
00106 
00107 #include "kexiuseraction.moc"
00108 
KDE Home | KDE Accessibility Home | Description of Access Keys