QString RyJsBridge::getConfigs(){ RyRuleManager *manager = RyRuleManager::instance(); QString s = manager->toJson(); s.remove('\r'); s.remove('\n'); s.remove('\t'); return s; }
QString RyJsBridge::doAction(int action, const QString msg, quint64 groupId){ qDebug()<<"doAction "<<QString::number(action)<< msg<<"groupId"<<QString::number(groupId); RyRuleManager *manager = RyRuleManager::instance(); QSharedPointer<RyRuleProject> pro; QSharedPointer<RyRuleGroup> group; QSharedPointer<RyRule> rule; switch(action){ case 0://add local group group = manager->addGroupToLocalProject(msg);//暂时只允许添加到本地project //emit ruleChanged(0,"success"); if(!group.isNull()){ qDebug()<<group->toJSON(); return group->toJSON(); } break; case 1://add rule to group rule = manager->addRuleToGroup(msg,groupId); if(!rule.isNull()){ //qDebug()<<QString::number(rule->ruleId()); //return QString::number(rule->ruleId()); return rule->toJSON(); } break; case 2://add remote project pro = manager->addRemoteProject(msg); if(!pro.isNull()){ emit ruleChanged(2,pro->toJson()); return pro->toJson(); } break; case 3://update group manager->updateRuleGroup(msg,groupId); break; case 4://update rule manager->updateRule(msg,groupId); break; case 5://remove group manager->removeGroup(msg.toULongLong()); break; case 6://remove rule (6,ruleId,groupId) manager->removeRule(msg.toULongLong(),groupId); break; case 7://import local config pro = manager->addLocalProject(msg); if(!pro.isNull()){ emit ruleChanged(2,pro->toJson()); return pro->toJson(); } break; } return ""; }
int main(int argc, char *argv[]) { QApplication a(argc, argv); a.setQuitOnLastWindowClosed(false); appPath = qApp->applicationDirPath(); QTranslator translator; bool isLoadSuccess = translator.load(appPath+"/rythem_zh_CN"); if(!isLoadSuccess)qDebug()<<"error"; QTextCodec::setCodecForTr(QTextCodec::codecForName("utf8")); a.installTranslator(&translator); #ifdef DEBUGTOFILE qInstallMsgHandler(myMessageHandler); #endif RyRuleManager *manager = RyRuleManager::instance(); manager->loadLocalConfig(appPath+"/rythem_config.txt"); // register metatypes qRegisterMetaType<RyPipeData_ptr>("RyPipeData_ptr"); QTextCodec::setCodecForTr(QTextCodec::codecForName("utf8")); //QTextCodec::setCodecForCStrings(QTextCodec::codecForName("utf8")); //QTextCodec::setCodecForLocale(QTextCodec::codecForName("utf8")); MainWindow w; RyProxyServer* server = RyProxyServer::instance(); server->connect(server,SIGNAL(pipeBegin(RyPipeData_ptr)),&w,SLOT(onNewPipe(RyPipeData_ptr))); server->connect(server,SIGNAL(pipeComplete(RyPipeData_ptr)),&w,SLOT(onPipeUpdate(RyPipeData_ptr))); server->connect(server,SIGNAL(pipeError(RyPipeData_ptr)),&w,SLOT(onPipeUpdate(RyPipeData_ptr))); server->listen(QHostAddress("127.0.0.1"),8889); //w.showMaximized(); w.show(); return a.exec(); }
int main(int argc, char *argv[]) { SingleApplication a(argc, argv, "a"); if(a.isRunning()){ a.sendMessage("from other instance"); return 0; } #ifdef Q_OS_MAC ProxyAutoConfig::instance(); #endif a.setQuitOnLastWindowClosed(false); appPath = qApp->applicationDirPath(); // load app translate file QTranslator translator; bool isLoadSuccess = translator.load(appPath+"/rythem_zh_CN"); if(!isLoadSuccess)qDebug()<<" load language error"; a.installTranslator(&translator); // load system translate file QTranslator translator2; translator2.load(appPath+"/qt_zh_CN"); a.installTranslator(&translator2); #ifdef DEBUGTOFILE qInstallMsgHandler(myMessageHandler); #endif RyRuleManager *manager = RyRuleManager::instance(); manager->loadLocalConfig(appPath+"/rythem_config.txt"); // register metatypes qRegisterMetaType<RyPipeData_ptr>("RyPipeData_ptr"); MainWindow w; //a.connect(&a,SIGNAL(messageAvailable(QString)),&w,SLOT(raise())); a.connect(&a,SIGNAL(messageAvailable(QString)),&w,SLOT(onMessageFromOtherInstance())); RyProxyServer* server = RyProxyServer::instance(); server->connect(server,SIGNAL(pipeBegin(RyPipeData_ptr)),&w,SLOT(onNewPipe(RyPipeData_ptr))); server->connect(server,SIGNAL(pipeComplete(RyPipeData_ptr)),&w,SLOT(onPipeUpdate(RyPipeData_ptr))); server->connect(server,SIGNAL(pipeError(RyPipeData_ptr)),&w,SLOT(onPipeUpdate(RyPipeData_ptr))); bool isListenSuccess = server->listen(QHostAddress::Any,8889); if(!isListenSuccess){ return 0; } qDebug()<<"listen success"; //w.showMaximized(); w.show(); return a.exec(); }