Ok, the long awaited config wizard is here (at least in a very basic state). There...
[quassel.git] / src / contrib / libqxt-2007-10-24 / src / web / qxtwebcontroller.cpp
1 /****************************************************************************
2 **
3 ** Copyright (C) Qxt Foundation. Some rights reserved.
4 **
5 ** This file is part of the QxtWeb  module of the Qt eXTension library
6 **
7 ** This library is free software; you can redistribute it and/or modify it
8 ** under the terms of th Common Public License, version 1.0, as published by
9 ** IBM.
10 **
11 ** This file is provided "AS IS", without WARRANTIES OR CONDITIONS OF ANY
12 ** KIND, EITHER EXPRESS OR IMPLIED INCLUDING, WITHOUT LIMITATION, ANY
13 ** WARRANTIES OR CONDITIONS OF TITLE, NON-INFRINGEMENT, MERCHANTABILITY OR
14 ** FITNESS FOR A PARTICULAR PURPOSE.
15 **
16 ** You should have received a copy of the CPL along with this file.
17 ** See the LICENSE file and the cpl1.0.txt file included with the source
18 ** distribution for more information. If you did not receive a copy of the
19 ** license, contact the Qxt Foundation.
20 **
21 ** <http://libqxt.org>  <foundation@libqxt.org>
22 **
23 ****************************************************************************/
24 #include "qxtwebcontroller.h"
25 #include "qxtwebcore.h"
26 #include <QStringList>
27 #include <QDebug>
28 #include <QCoreApplication>
29 #include <QUrl>
30 static QTextStream  nullstream;
31
32 QString QxtWebController::WebRoot()
33 {
34
35     return QCoreApplication::applicationDirPath()+"/../";
36 }
37
38
39 QxtWebController::QxtWebController(QString name):QObject(QCoreApplication::instance())
40 {
41     stream_m=0;
42     setObjectName(name);
43 }
44
45
46 QTextStream & QxtWebController::echo()
47 {
48     if (!stream_m)
49     {
50         qDebug("QxtWebController::echo() no stream open");
51         return nullstream;
52     }
53     return *stream_m;
54 }
55
56
57 QString QxtWebController::self()
58 {
59     return "/"+objectName();
60 }
61
62
63 int QxtWebController::invoke(server_t & SERVER_i)
64 {
65     SERVER=SERVER_i;
66     QList<QByteArray> args_d = SERVER["REQUEST_URI"].split('/');
67
68     ///--------------find action ------------------
69     QByteArray action="index";
70     if (args_d.count()>2)
71     {
72         action=args_d.at(2);
73         if (action.trimmed().isEmpty())action="index";
74     }
75     else if (args_d.count()>1)
76         action="index";
77
78
79     if (args_d.count()>3)
80     {
81         args_d.removeFirst();
82         args_d.removeFirst();
83         args_d.removeFirst();
84     }
85     else
86         args_d.clear();
87
88     QStringList args;
89     foreach(QByteArray arg,args_d)
90     args<<QUrl::fromPercentEncoding(arg);
91
92     QByteArray buffer;
93     QTextStream strm (&buffer);
94     stream_m=  &strm;
95
96     int retVal=666;
97     if (args.count()>8)
98     {
99         if (!QMetaObject::invokeMethod(this, action,Q_RETURN_ARG(int, retVal) ,
100                                        Q_ARG(QString, args.at(0)),Q_ARG(QString, args.at(1)),Q_ARG(QString, args.at(2)),Q_ARG(QString, args.at(3))
101                                        ,Q_ARG(QString, args.at(4)),Q_ARG(QString, args.at(5)),Q_ARG(QString, args.at(6)),Q_ARG(QString, args.at(8))))
102         {
103             retVal=4042; ///FIXME: the return value of the invoke has a meaning, handle it!
104         }
105     }
106     else if (args.count()>7)
107     {
108         if (!QMetaObject::invokeMethod(this, (action),Q_RETURN_ARG(int, retVal) ,
109                                        Q_ARG(QString, args.at(0)),Q_ARG(QString, args.at(1)),Q_ARG(QString, args.at(2)),Q_ARG(QString, args.at(3))
110                                        ,Q_ARG(QString, args.at(4)),Q_ARG(QString, args.at(5)),Q_ARG(QString, args.at(6)),Q_ARG(QString, args.at(7))
111                                       ))
112         {
113             retVal=4042;
114         }
115
116     }
117     else if (args.count()>6)
118     {
119         if ( !QMetaObject::invokeMethod(this, (action),Q_RETURN_ARG(int, retVal) ,
120                                         Q_ARG(QString, args.at(0)),Q_ARG(QString, args.at(1)),Q_ARG(QString, args.at(2)),Q_ARG(QString, args.at(3))
121                                         ,Q_ARG(QString, args.at(4)),Q_ARG(QString, args.at(5)),Q_ARG(QString, args.at(6))
122                                        ))
123         {
124             retVal=4042;
125         }
126     }
127     else if (args.count()>5)
128     {
129         if (!QMetaObject::invokeMethod(this, (action),Q_RETURN_ARG(int, retVal) ,
130                                        Q_ARG(QString, args.at(0)),Q_ARG(QString, args.at(1)),Q_ARG(QString, args.at(2)),Q_ARG(QString, args.at(3))
131                                        ,Q_ARG(QString, args.at(4)),Q_ARG(QString, args.at(5))
132                                       ))
133         {
134             retVal=4042;
135         }
136     }
137     else if ( args.count()>4)
138     {
139         if ( !QMetaObject::invokeMethod(this, (action),Q_RETURN_ARG(int, retVal) ,
140                                         Q_ARG(QString, args.at(0)),Q_ARG(QString, args.at(1)),Q_ARG(QString, args.at(2)),Q_ARG(QString, args.at(3))
141                                         ,Q_ARG(QString, args.at(4))
142                                        ))
143         {
144             retVal=4042;
145         }
146     }
147     else if (args.count()>3)
148     {
149         if ( !QMetaObject::invokeMethod(this, (action),Q_RETURN_ARG(int, retVal) ,
150                                         Q_ARG(QString, args.at(0)),Q_ARG(QString, args.at(1)),Q_ARG(QString, args.at(2)),Q_ARG(QString, args.at(3))
151                                        ))
152         {
153             retVal=4042;
154         }
155     }
156     else if (args.count()>2)
157     {
158         if ( !QMetaObject::invokeMethod(this, (action),Q_RETURN_ARG(int, retVal) ,
159                                         Q_ARG(QString, args.at(0)),Q_ARG(QString, args.at(1)),Q_ARG(QString, args.at(2))
160                                        ))
161             retVal=4042;
162     }
163     else if (args.count()>1)
164     {
165         if ( !QMetaObject::invokeMethod(this, (action),Q_RETURN_ARG(int, retVal) ,
166                                         Q_ARG(QString, args.at(0)),Q_ARG(QString, args.at(1))
167                                        ))
168             retVal=4042;
169     }
170     else if (args.count()>0)
171     {
172         if ( !QMetaObject::invokeMethod(this, (action),Q_RETURN_ARG(int, retVal) ,Q_ARG(QString, args.at(0))))
173             retVal=4042;
174     }
175     else
176     {
177         if ( !QMetaObject::invokeMethod(this, (action),Q_RETURN_ARG(int, retVal) ))
178         {
179             retVal=4042;
180         }
181     }
182
183     stream_m->flush ();
184     stream_m=0;
185     if(buffer.size())
186         QxtWebCore::send(buffer);
187     return retVal;
188 };
189
190
191
192
193