createMenuBar();
connectDB();
statusBar()->addPermanentWidget(label);
- toggleMenu();
start();
}
void MainWindow::start(){
show();
#endif
}
-void MainWindow::choosehost(){
- bool ok=0;
- host=QInputDialog::getText(this, QString("Host"), QString("Enter hostname (or ip)"), QLineEdit::Normal, host, &ok);
- if(ok==1)conf->setValue(QString("host"), host);
-}
-void MainWindow::chooseuser(){
- bool ok=0;
- user=QInputDialog::getText(this, QString("Username"), QString("Enter username"), QLineEdit::Normal, user, &ok);
- if(ok==1)conf->setValue(QString("user"), user);
-}
-void MainWindow::choosepass(){
- bool ok=0;
- password=QInputDialog::getText(this, QString("Password"), QString("Enter password"), QLineEdit::PasswordEchoOnEdit, password, &ok);
- if(ok==1)conf->setValue(QString("password"), password);
-}
-void MainWindow::choosedb(){
- bool ok=0;
- database=QInputDialog::getText(this, QString("Database name"), QString("Enter database name"), QLineEdit::Normal, database, &ok);
- if(ok==1)conf->setValue(QString("database"), database);
-}
-void MainWindow::chooseport(){
-
- bool ok;
- port=QInputDialog::getInt(this, QString("port ?"), QString("quel port ?"), port, 1, 65535, 1, &ok);
- if((ok==1)){
- conf->setValue(QString("port"), port);
- }else{
- port=22;
- }
-}
-void MainWindow::choosefile(){
- bool ok=0;
- file=QFileDialog::getSaveFileName(this, tr("Open file to write into"), file);
- if (ok)conf->setValue(QString("file"), file);
-
-}
-void MainWindow::choosemaxc(){
- bool ok;
- int maxc=QInputDialog::getInt(this, QString("colonne"), QString("colonne max ?"), conf->value(QString("maxcolumn")).toInt(), 1, 65535, 1, &ok);
- if((ok==1)){
- conf->setValue(QString("maxcolumn"), maxc);
- }else{
- conf->setValue(QString("maxcolumn"), conf->value(QString("maxcolumn")).toInt());
- }
-}
void MainWindow::lsconfig(){
flush();
QStringList tmp=conf->allKeys();
qDebug()<<"action("<<a<<")";
label->setText(a);
flush();
- /*if (a=="host")choosehost(); done
- else if (a=="port")chooseport(); done
- else if (a=="user")chooseuser(); done
- else if (a=="database")choosedb();
- else if (a=="password")choosepass();
- else if (a=="file")choosefile();
- else if (a=="maxcolumn")choosemaxc();*/
if (a.split(QString(" "))[0]==QString("set")){
- conf->setValue(QString(a.split(QString(" "))[1]), a.split(QString(" "))[2]);
-}
-
+ conf->setValue(QString(a.split(QString(" "))[1]), a.split(QString(" "))[2]);
+ }
+ else if(a.split(QString(" "))[0]==QString("sql ")){
+ exec(a.mid(4));
+ }
else getButtons(a);
}
void MainWindow::createMenuBar(){
FileMenu=new QMenu(QString("&File"), this);
- FileMenu->addAction(tr("&Start..."), this, SLOT(start()),QKeySequence(tr("Ctrl+S", "Start")));
- FileMenu->addAction(tr("&Connect"), this, SLOT(connectDB()),QKeySequence(tr("Ctrl+C", "Connect")));
- FileMenu->addAction(tr("&Quit..."), this, SLOT(quit()),QKeySequence(tr("Ctrl+Q", "Quit")));
+ FileMenu->addAction(trUtf8("&Start..."), this, SLOT(start()),QKeySequence(trUtf8("Ctrl+S", "Start")));
+ FileMenu->addAction(trUtf8("&Connect"), this, SLOT(connectDB()),QKeySequence(trUtf8("Ctrl+C", "Connect")));
+ FileMenu->addAction(trUtf8("&Quit..."), this, SLOT(quit()),QKeySequence(trUtf8("Ctrl+Q", "Quit")));
menuBar()->addMenu(FileMenu);
EditMenu=new QMenu(QString("&Edit"));
- EditMenu->addAction(tr("Co&nfig"), this, SLOT(lsconfig()), QKeySequence(tr("Ctrl+N", "Edit|Co&nfig")));
- EditMenu->addAction(tr("C&reate database"), this, SLOT(createDB()), QKeySequence(tr("Ctrl+R", "Edit|Database")));
- EditMenu->addAction(tr("A&dd buttons"), this, SLOT(addButtonDB()), QKeySequence(tr("Ctrl+D", "Add buttons")));
+ EditMenu->addAction(trUtf8("Co&nfig"), this, SLOT(lsconfig()), QKeySequence(trUtf8("Ctrl+N", "Edit|Co&nfig")));
+ EditMenu->addAction(trUtf8("C&reate database"), this, SLOT(createDB()), QKeySequence(trUtf8("Ctrl+R", "Edit|Database")));
+ EditMenu->addAction(trUtf8("A&dd buttons"), this, SLOT(addButtonDB()), QKeySequence(trUtf8("Ctrl+D", "Add buttons")));
+ EditMenu->addAction(trUtf8("&Edit buttons"), this, SLOT(editButtonDB()), QKeySequence(trUtf8("Ctrl+E", "Edit|&Edit button")));
menuBar()->addMenu(EditMenu);
HelpMenu=new QMenu(QString("&Help"));
HelpMenu->addAction(tr("About Qt"), qApp, SLOT(aboutQt()), QKeySequence(tr("ctrl+H", "About Qt")));
}
widget.clear();
}
-void MainWindow::editConf(const QString & a){
- label=new QLabel(a);
- texte=new QLineEdit(conf->value(a).toString());
- CLabel * button=new CLabel(QString("ok"));
- grid->addWidget(label, 1, 0);
- grid->addWidget(texte, 1, 1);
- grid->addWidget(button, 1,2);
- connect(button, SIGNAL(released()), this, SLOT(confChanged()));
-
-}
-void MainWindow::confChanged(){
- conf->setValue(label->text(), texte->text());
- start();
-}
CLabel::CLabel( const QString& text, QWidget * parent ) : QLabel(parent)
{
setText(text);
setWordWrap(true);
setLineWidth(5);
- setStyleSheet("background-color: red;border-style: outset;border-width: 7px;border-radius: 10px;border-color: beige;font: bold 10px;padding: 6px;");
+ setStyleSheet("background-color: red;border-style: outset;border-width: 7px;border-radius: 10px;border-color: beige;font: bold 15px;padding: 6px;");
setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::MinimumExpanding);
}
q->next();
}
}
-void MainWindow::connected(){
+/*void MainWindow::connected(){
label->setText(QString("Online"));
qDebug()<<"connected !!!";
}
void MainWindow::TCPerrors(QAbstractSocket::SocketError a){
qDebug()<<"erreurs TCP : "<< a;
//ssl->disconnect();
-}
+}*/
QString MainWindow::getText(const QString &a){
return widget.value(a)->text();
}
return tmp;
}
int MainWindow::exec(const QString & a){
- qDebug()<<"exec("<<a<<")";
+ //qDebug()<<"exec("<<a<<")";
q->prepare(a);
q->exec();
QSqlError b=q->lastError();
void MainWindow::createDB(){
exec(QString("create table ui(keyword text, label text, action text);"));
exec(QString("create table raw(date timestamp, texte text);"));
+
}
void MainWindow::addButtonDB(){
QString cmd="insert into ui (keyword, label, action) values ('";
addWidget(q->value(actCol).toString(), new CLabel(q->value(labCol).toString()));
}
}
+void MainWindow::editButtonDB(){
+ flush();
+ exec(QString("select distinct keyword from ui"));
+ while (q->next()) {
+ QString key=QString("sql select label from ui where keyword='"+q->value(0).toString()+"';");
+ addWidget(key, new CLabel(q->value(0).toString()));
+ }
+}
INSERT INTO ui ('keyword', 'label', 'action') VALUES('lieu', 'odysseum', 'l-odysseum');
INSERT INTO ui ('keyword', 'label', 'action') VALUES('l-odysseum', 'subway', 'l-o-subway');
INSERT INTO ui ('keyword', 'label', 'action') VALUES('l-o-subway', 'julie', 'l-o-s-julie');
- INSERT INTO ui ('keyword', 'label', 'action') VALUES('l-odysseum', 'oliver''s pub', 'l-o-op');
- INSERT INTO ui ('keyword', 'label', 'action') VALUES('l-o-op', 'valentine', 'l-o-opub-val');
+ INSERT INTO ui ('keyword', 'label', 'action') VALUES('l-odysseum', 'oliver''s pub', 'l-o-oliver');
+ INSERT INTO ui ('keyword', 'label', 'action') VALUES('l-o-oliver', 'valentine', 'l-o-opub-val');
INSERT INTO ui ('keyword', 'label', 'action') VALUES('l-o-opub-val', 's''enerve quand je lui demande ce qu''elle veut', 'begin');
--config buttons
INSERT INTO ui ('keyword', 'label', 'action') VALUES('begin', 'config', 'config');
INSERT INTO ui ('keyword', 'label', 'action') VALUES('c-user', 'android', 'set user android');
INSERT INTO ui ('keyword', 'label', 'action') VALUES('config', 'password', 'c-pass'); -- I highly discourage to set pass in a public zone !
INSERT INTO ui ('keyword', 'label', 'action') VALUES('c-pass', '123', 'set pass 123'); -- "
- INSERT INTO ui ('keyword', 'label', 'action') VALUES('config', 'db', 'c-db');
- INSERT INTO ui ('keyword', 'label', 'action') VALUES('c-db', 'chat', 'set db chat');
+ INSERT INTO ui ('keyword', 'label', 'action') VALUES('config', 'database', 'c-db');
+ INSERT INTO ui ('keyword', 'label', 'action') VALUES('c-db', 'chat', 'set database chat');
+ INSERT INTO ui ('keyword', 'label', 'action') VALUES('c-db', 'chien', 'set database chien');