void Connection::saveConfig (QString const & preset_name) { QString const path = mkAppPresetPath(getGlobalConfig().m_appdir, getAppName(), preset_name); mkPath(path); QString const fname = path + "/" + getAppName() + ".xml"; saveConfigTemplate(m_config, fname); }
IContentItem* CRootItem::addContentItem(string text, int posInParent) throw (ExMalformedPatch) { string path = stripFirstSection(text); CItemType itemType = getItemType(text); if(itemType.getType() == CItemType::E_INVAL ) { throw ExMalformedPatch("invalid item type", -1); } CCategoryItem* parent = getCategoryPtr(path); if(parent == 0) { parent = mkPath(path); } //beginInsertItems(posInParent, 1, parent ); IContentItem* newItem = IContentItem::itemFactory( itemType, this, text, parent, posInParent); //endInsertItems(); return newItem; }
void Connection::onDisconnected () { qDebug("onDisconnected()"); m_main_window->saveDefaultPreset(); if (m_main_window->dumpModeEnabled()) { QString const path = tr("%1_%2").arg(getAppName()).arg(m_pid); if (mkPath(path)) onExportDataToCSV(path); m_main_window->markConnectionForClose(this); } for (dataplots_t::iterator it = m_data.get<e_data_plot>().begin(), ite = m_data.get<e_data_plot>().end(); it != ite; ++it) (*it)->stopUpdate(); }
void CRootItem::patch(std::string diff) throw(ExMalformedPatch) { istringstream iss(diff); CCategoryItem* parent = 0; bool new_category = true; boost::regex rx("^@@ -(\\d+),(\\d+)\\s+\\+(\\d+),(\\d+)\\s*@@$"); int oldStart(0); int oldLen(0); int newStart(0); int newLen(0); int lineNr = 0; int patchLineNr = 0; int chunkSizeSum = 0; string line; while(!iss.eof()) { getline(iss, line); if(iss.bad()) { cerr << "CRootItem::patch: Error reading lines." << endl; } patchLineNr++; if( line.find("+++ ") == 0 ) { // new or modified category string path = line.substr(4, line.size() - 4); parent = getCategoryPtr(path); if(parent == 0) { parent = mkPath(path); } new_category = true; chunkSizeSum = 0; } else if(line.find("--- ") == 0) { // remove a complete category string path = line.substr(4, line.size() - 4); CCategoryItem *categoryToRemove = getCategoryPtr(path); if(categoryToRemove == 0) { ostringstream oss; oss << "CRootItem::patch (__FILE__:__LINE__): the category item to be removed was not be found in current collection(" << path << ")."; throw ExMalformedPatch(oss.str(), patchLineNr); } CCategoryItem* parent = categoryToRemove->getParent(); parent->delCategory(categoryToRemove); /// TODO really remove category here chunkSizeSum = 0; new_category = true; } else if( line.find("@@") == 0 ) { // diff chunk header boost::cmatch res; boost::regex_search(line.c_str(), res, rx); string oldStartStr = res[1]; string oldLenStr = res[2]; string newStartStr = res[3]; string newLenStr = res[4]; try { oldStart = CUtils::str2long( oldStartStr ); oldLen = CUtils::str2long( oldLenStr ); newStart = CUtils::str2long( newStartStr ); newLen = CUtils::str2long( newLenStr ); } catch(std::invalid_argument& ex) { throw ExMalformedPatch(ex.what(), lineNr); } if(oldLen == 0) oldStart++; lineNr = oldStart + chunkSizeSum; chunkSizeSum += newLen - oldLen; new_category = false; // cerr << "- << oldStart << "," << oldLen << " + " << newStart << "," << newLen << endl; } else if( line.size() > 0 ) { char sign = line[0]; string content = line.substr(1, line.size() - 1); assert(new_category == false); switch(sign){ case '+': //insert { //cerr << "adding line : << lineNr << endl;; //cerr << "from diff : "<< content << endl; IContentItem* newItem = addContentItem(content, lineNr - 1); break; } case '-': //remove { string path = stripFirstSection(content); parent = getCategoryPtr(path); if(parent == 0) { ostringstream oss; oss << "error removing item: unknown parent category '" << path << "'"; throw ExMalformedPatch(oss.str(), patchLineNr); } if((lineNr - 1) < 0 || (lineNr - 1) > parent->getNumContentItems() ) { ostringstream oss; oss << "error: request to remove item at " << lineNr - 1 << " in category '" << path << "' outside valid range [0, " << parent->getNumContentItems() << "]."; throw ExMalformedPatch(oss.str(), patchLineNr); } IContentItem *contItem = parent->getContentItem(lineNr - 1); string itemText = contItem->getText(); if(itemText.compare(0, itemText.size() - 1, content) != 0 ) // possible error: { cerr << "Error when removing line " << lineNr << " :" << endl; cerr << "line expected from diff : "<< content << endl; cerr << "differs form collection : " << contItem->getText(); } parent->delContentItem(lineNr - 1); lineNr--; break; } case ' ': //check { IContentItem *contItem = parent->getContentItem(lineNr - 1); string itemText = contItem->getText(); if(itemText.compare(0, itemText.size() - 1, content) != 0 ) // possible error: { cerr << "Error when keeping line " << lineNr << " :" << endl; cerr << "line expected from diff : "<< content << endl; cerr << "differs form collection : " << contItem->getText(); } break; } default: break; } lineNr++; } } }
int main (int argc, char * argv[]) { sys::setTimeStart(); QString const path = QDir::homePath() + "/" + g_traceServerDirName + "/logs"; mkPath(path); QFileInfo fi(argv[0]); QString const log_name = path + "/" + QString("%1.%2").arg(fi.completeBaseName()).arg("log"); g_LogRedirect = fopen(log_name.toLatin1(), "w"); bool quit_delay = true; bool start_hidden = false; bool dump_mode = false; int level = -1; for (int i = 1; i < argc; ++i) { if (argv[i][0] != '-') { //foo.push_back(argv[i]); continue; } // if there's a flag but no argument following, ignore it if (argc == i) continue; char const * arg = argv[i+1]; switch (argv[i][1]) { case 'q': printf("cmd arg: -q, quit immeadiately\n"); quit_delay = false; break; case 'd': printf("cmd arg: -d, dump mode\n"); dump_mode = true; break; case 'n': printf("cmd arg: -n, no visible window\n"); start_hidden = true; break; case 'l': level = std::atoi(arg); printf("cmd arg: -l, start at level %i\n", level); break; case 'h': usage(); return 0; default: printf("Invalid option, use -h for Help\n"); return 0; } } if (g_LogRedirect) qInstallMessageHandler(qDebugHandler); Application app(argc, argv); app.setOrganizationName(g_OrganizationName); app.setApplicationName(g_TraceServerAppName); #ifdef WIN32 if (!QSystemTrayIcon::isSystemTrayAvailable()) { QMessageBox::critical(0, QObject::tr("Systray"), QObject::tr("I couldn't detect any system tray on this system.")); return 1; } #endif MainWindow w(0, quit_delay, dump_mode, log_name, level); if (!start_hidden) { w.setVisible(true); w.show(); } app.setMainWindow(&w); if (start_hidden) w.onHotkeyShowOrHide(); bool const retval = app.exec(); // main loop qInstallMessageHandler(0); if (g_LogRedirect) fclose(g_LogRedirect); return retval; }