/* ** Print an error message and then quit. */ static void fatalError(const char *zFormat, ...){ va_list ap; char *zMsg; char zPrefix[30]; va_start(ap, zFormat); zMsg = sqlite3_vmprintf(zFormat, ap); va_end(ap); sqlite3_snprintf(sizeof(zPrefix), zPrefix, "%s:FATAL: ", g.zName); if( g.pLog ){ printWithPrefix(g.pLog, zPrefix, zMsg); fflush(g.pLog); maybeClose(g.pLog); } if( g.pErrLog && safe_strcmp(g.zErrLog,g.zLog) ){ printWithPrefix(g.pErrLog, zPrefix, zMsg); fflush(g.pErrLog); maybeClose(g.pErrLog); } sqlite3_free(zMsg); if( g.db ){ int nTry = 0; g.iTimeout = 0; while( trySql("UPDATE client SET wantHalt=1;")==SQLITE_BUSY && (nTry++)<100 ){ sqlite3_sleep(10); } } sqlite3_close(g.db); exit(1); }
/** * @brief Catch the closeEvent. * @details Launch maybeClose() to ask the user if he really want to quit. * If so close the windows * * @param event The close Event */ void MainWindow::closeEvent(QCloseEvent *event) { if (maybeClose()) { event->accept(); } else { event->ignore(); } }
int sqlite_test() { const char *zClient; int iClient; int n, i; int openFlags = SQLITE_OPEN_READWRITE; int rc; char *zScript; int taskId; const char *zTrace; const char *zCOption; g.argv0 = argv[0]; g.iTrace = 1; if( argc<2 ) usage(argv[0]); g.zDbFile = argv[1]; if( strglob("*.test", g.zDbFile) ) usage(argv[0]); if( strcmp(sqlite3_sourceid(), SQLITE_SOURCE_ID)!=0 ){ fprintf(stderr, "SQLite library and header mismatch\n" "Library: %s\n" "Header: %s\n", sqlite3_sourceid(), SQLITE_SOURCE_ID); exit(1); } n = argc-2; sqlite3_snprintf(sizeof(g.zName), g.zName, "%05d.mptest", GETPID()); g.zVfs = findOption(argv+2, &n, "vfs", 1); zClient = findOption(argv+2, &n, "client", 1); g.zErrLog = findOption(argv+2, &n, "errlog", 1); g.zLog = findOption(argv+2, &n, "log", 1); zTrace = findOption(argv+2, &n, "trace", 1); if( zTrace ) g.iTrace = atoi(zTrace); if( findOption(argv+2, &n, "quiet", 0)!=0 ) g.iTrace = 0; g.bSqlTrace = findOption(argv+2, &n, "sqltrace", 0)!=0; g.bSync = findOption(argv+2, &n, "sync", 0)!=0; if( g.zErrLog ){ g.pErrLog = fopen(g.zErrLog, "a"); }else{ g.pErrLog = stderr; } if( g.zLog ){ g.pLog = fopen(g.zLog, "a"); }else{ g.pLog = stdout; } sqlite3_config(SQLITE_CONFIG_LOG, sqlErrorCallback, 0); if( zClient ){ iClient = atoi(zClient); if( iClient<1 ) fatalError("illegal client number: %d\n", iClient); sqlite3_snprintf(sizeof(g.zName), g.zName, "%05d.client%02d", GETPID(), iClient); }else{ if( g.iTrace>0 ){ printf("With SQLite " SQLITE_VERSION " " SQLITE_SOURCE_ID "\n" ); for(i=0; (zCOption = sqlite3_compileoption_get(i))!=0; i++){ printf("-DSQLITE_%s\n", zCOption); } fflush(stdout); } iClient = 0; unlink(g.zDbFile); openFlags |= SQLITE_OPEN_CREATE; } rc = sqlite3_open_v2(g.zDbFile, &g.db, openFlags, g.zVfs); if( rc ) fatalError("cannot open [%s]", g.zDbFile); sqlite3_enable_load_extension(g.db, 1); sqlite3_busy_handler(g.db, busyHandler, 0); sqlite3_create_function(g.db, "vfsname", 0, SQLITE_UTF8, 0, vfsNameFunc, 0, 0); sqlite3_create_function(g.db, "eval", 1, SQLITE_UTF8, 0, evalFunc, 0, 0); g.iTimeout = DEFAULT_TIMEOUT; if( g.bSqlTrace ) sqlite3_trace(g.db, sqlTraceCallback, 0); if( !g.bSync ) trySql("PRAGMA synchronous=OFF"); if( iClient>0 ){ if( n>0 ) unrecognizedArguments(argv[0], n, argv+2); if( g.iTrace ) logMessage("start-client"); while(1){ char *zTaskName = 0; rc = startScript(iClient, &zScript, &taskId, &zTaskName); if( rc==SQLITE_DONE ) break; if( g.iTrace ) logMessage("begin %s (%d)", zTaskName, taskId); runScript(iClient, taskId, zScript, zTaskName); if( g.iTrace ) logMessage("end %s (%d)", zTaskName, taskId); finishScript(iClient, taskId, 0); sqlite3_free(zTaskName); sqlite3_sleep(10); } if( g.iTrace ) logMessage("end-client"); }else{ sqlite3_stmt *pStmt; int iTimeout; if( n==0 ){ fatalError("missing script filename"); } if( n>1 ) unrecognizedArguments(argv[0], n, argv+2); runSql( "CREATE TABLE task(\n" " id INTEGER PRIMARY KEY,\n" " name TEXT,\n" " client INTEGER,\n" " starttime DATE,\n" " endtime DATE,\n" " script TEXT\n" ");" "CREATE INDEX task_i1 ON task(client, starttime);\n" "CREATE INDEX task_i2 ON task(client, endtime);\n" "CREATE TABLE counters(nError,nTest);\n" "INSERT INTO counters VALUES(0,0);\n" "CREATE TABLE client(id INTEGER PRIMARY KEY, wantHalt);\n" ); zScript = readFile(argv[2]); if( g.iTrace ) logMessage("begin script [%s]\n", argv[2]); runScript(0, 0, zScript, argv[2]); sqlite3_free(zScript); if( g.iTrace ) logMessage("end script [%s]\n", argv[2]); waitForClient(0, 2000, "during shutdown...\n"); trySql("UPDATE client SET wantHalt=1"); sqlite3_sleep(10); g.iTimeout = 0; iTimeout = 1000; while( ((rc = trySql("SELECT 1 FROM client"))==SQLITE_BUSY || rc==SQLITE_ROW) && iTimeout>0 ){ sqlite3_sleep(10); iTimeout -= 10; } sqlite3_sleep(100); pStmt = prepareSql("SELECT nError, nTest FROM counters"); iTimeout = 1000; while( (rc = sqlite3_step(pStmt))==SQLITE_BUSY && iTimeout>0 ){ sqlite3_sleep(10); iTimeout -= 10; } if( rc==SQLITE_ROW ){ g.nError += sqlite3_column_int(pStmt, 0); g.nTest += sqlite3_column_int(pStmt, 1); } sqlite3_finalize(pStmt); } sqlite3_close(g.db); maybeClose(g.pLog); maybeClose(g.pErrLog); if( iClient==0 ){ printf("Summary: %d errors in %d tests\n", g.nError, g.nTest); } return g.nError>0; }
void PopupView::init() { if (m_model) { return; } m_scene = new QGraphicsScene(this); m_view = new QGraphicsView(m_scene, this); m_view->setFrameShape(QFrame::NoFrame); m_view->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff); m_view->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff); m_view->viewport()->setAutoFillBackground(false); m_view->setGeometry(contentsRect()); m_view->show(); DirLister *lister = new DirLister(this); lister->setDelayedMimeTypes(true); lister->setAutoErrorHandlingEnabled(false, 0); lister->openUrl(m_url); m_dirModel = new KDirModel(this); m_dirModel->setDropsAllowed(KDirModel::DropOnDirectory | KDirModel::DropOnLocalExecutable); m_dirModel->setDirLister(lister); m_model = new ProxyModel(this); m_model->setSourceModel(m_dirModel); m_model->setSortLocaleAware(m_parentViewModel->isSortLocaleAware()); m_model->setParseDesktopFiles(m_parentViewModel->parseDesktopFiles()); m_model->setFilterMode(m_parentViewModel->ProxyModel::NoFilter); m_model->setDynamicSortFilter(true); if (!m_parentViewModel->dynamicSortFilter()) { m_model->setSortDirectoriesFirst(true); m_model->sort(int(KDirModel::Name), Qt::AscendingOrder); } else { m_model->setSortDirectoriesFirst(m_parentViewModel->sortDirectoriesFirst()); m_model->sort(m_parentViewModel->sortColumn(), m_parentViewModel->sortOrder()); } m_delegate = new KFileItemDelegate(this); m_selectionModel = new QItemSelectionModel(m_model, this); m_iconView = new IconView(0); m_iconView->setModel(m_model); m_iconView->setItemDelegate(m_delegate); m_iconView->setSelectionModel(m_selectionModel); m_iconView->setFont(m_parentView->font()); m_iconView->setPalette(palette()); m_iconView->setDrawShadows(m_parentView->drawShadows()); m_iconView->setIconSize(m_parentView->iconSize()); m_iconView->setGridSize(m_parentView->gridSize()); m_iconView->setTextLineCount(m_parentView->textLineCount()); m_iconView->setWordWrap(m_parentView->wordWrap()); m_iconView->setIconsMoveable(false); m_iconView->setClickToViewFolders(false); m_iconView->setShowSelectionMarker(m_parentView->showSelectionMarker()); connect(m_iconView, SIGNAL(activated(QModelIndex)), SLOT(activated(QModelIndex))); connect(m_iconView, SIGNAL(contextMenuRequest(QWidget*,QPoint)), SLOT(contextMenuRequest(QWidget*,QPoint))); connect(m_iconView, SIGNAL(busy(bool)), SLOT(setBusy(bool))); connect(m_iconView, SIGNAL(popupViewClosed()), SLOT(maybeClose())); FolderViewAdapter *adapter = new FolderViewAdapter(m_iconView); m_previewGenerator = new KFilePreviewGenerator(adapter, m_model); m_previewGenerator->setPreviewShown(m_showPreview); m_previewGenerator->setEnabledPlugins(m_previewPlugins); m_iconView->setGeometry(contentsRect()); m_iconView->show(); m_scene->addItem(m_iconView); setBusy(true); }
int SQLITE_CDECL main(int argc, char **argv){ const char *zClient; int iClient; int n, i; int openFlags = SQLITE_OPEN_READWRITE; int rc; char *zScript; int taskId; const char *zTrace; const char *zCOption; const char *zJMode; const char *zNRep; int nRep = 1, iRep; int iTmout = 0; /* Default: no timeout */ const char *zTmout; g.argv0 = argv[0]; g.iTrace = 1; if( argc<2 ) usage(argv[0]); g.zDbFile = argv[1]; if( strglob("*.test", g.zDbFile) ) usage(argv[0]); if( strcmp(sqlite3_sourceid(), SQLITE_SOURCE_ID)!=0 ){ fprintf(stderr, "SQLite library and header mismatch\n" "Library: %s\n" "Header: %s\n", sqlite3_sourceid(), SQLITE_SOURCE_ID); exit(1); } n = argc-2; sqlite3_snprintf(sizeof(g.zName), g.zName, "%05d.mptest", GETPID()); zJMode = findOption(argv+2, &n, "journalmode", 1); zNRep = findOption(argv+2, &n, "repeat", 1); if( zNRep ) nRep = atoi(zNRep); if( nRep<1 ) nRep = 1; g.zVfs = findOption(argv+2, &n, "vfs", 1); zClient = findOption(argv+2, &n, "client", 1); g.zErrLog = findOption(argv+2, &n, "errlog", 1); g.zLog = findOption(argv+2, &n, "log", 1); zTrace = findOption(argv+2, &n, "trace", 1); if( zTrace ) g.iTrace = atoi(zTrace); if( findOption(argv+2, &n, "quiet", 0)!=0 ) g.iTrace = 0; zTmout = findOption(argv+2, &n, "timeout", 1); if( zTmout ) iTmout = atoi(zTmout); g.bSqlTrace = findOption(argv+2, &n, "sqltrace", 0)!=0; g.bSync = findOption(argv+2, &n, "sync", 0)!=0; if( g.zErrLog ){ g.pErrLog = fopen(g.zErrLog, "a"); }else{ g.pErrLog = stderr; } if( g.zLog ){ g.pLog = fopen(g.zLog, "a"); }else{ g.pLog = stdout; } sqlite3_config(SQLITE_CONFIG_LOG, sqlErrorCallback, 0); if( zClient ){ iClient = atoi(zClient); if( iClient<1 ) fatalError("illegal client number: %d\n", iClient); sqlite3_snprintf(sizeof(g.zName), g.zName, "%05d.client%02d", GETPID(), iClient); }else{ int nTry = 0; if( g.iTrace>0 ){ printf("BEGIN: %s", argv[0]); for(i=1; i<argc; i++) printf(" %s", argv[i]); printf("\n"); printf("With SQLite " SQLITE_VERSION " " SQLITE_SOURCE_ID "\n" ); for(i=0; (zCOption = sqlite3_compileoption_get(i))!=0; i++){ printf("-DSQLITE_%s\n", zCOption); } fflush(stdout); } iClient = 0; do{ if( (nTry%5)==4 ) printf("... %strying to unlink '%s'\n", nTry>5 ? "still " : "", g.zDbFile); rc = unlink(g.zDbFile); if( rc && errno==ENOENT ) rc = 0; }while( rc!=0 && (++nTry)<60 && sqlite3_sleep(1000)>0 ); if( rc!=0 ){ fatalError("unable to unlink '%s' after %d attempts\n", g.zDbFile, nTry); } openFlags |= SQLITE_OPEN_CREATE; } rc = sqlite3_open_v2(g.zDbFile, &g.db, openFlags, g.zVfs); if( rc ) fatalError("cannot open [%s]", g.zDbFile); if( iTmout>0 ) sqlite3_busy_timeout(g.db, iTmout); if( zJMode ){ #if defined(_WIN32) if( sqlite3_stricmp(zJMode,"persist")==0 || sqlite3_stricmp(zJMode,"truncate")==0 ){ printf("Changing journal mode to DELETE from %s", zJMode); zJMode = "DELETE"; } #endif runSql("PRAGMA journal_mode=%Q;", zJMode); } if( !g.bSync ) trySql("PRAGMA synchronous=OFF"); sqlite3_enable_load_extension(g.db, 1); sqlite3_busy_handler(g.db, busyHandler, 0); sqlite3_create_function(g.db, "vfsname", 0, SQLITE_UTF8, 0, vfsNameFunc, 0, 0); sqlite3_create_function(g.db, "eval", 1, SQLITE_UTF8, 0, evalFunc, 0, 0); g.iTimeout = DEFAULT_TIMEOUT; if( g.bSqlTrace ) sqlite3_trace(g.db, sqlTraceCallback, 0); if( iClient>0 ){ if( n>0 ) unrecognizedArguments(argv[0], n, argv+2); if( g.iTrace ) logMessage("start-client"); while(1){ char *zTaskName = 0; rc = startScript(iClient, &zScript, &taskId, &zTaskName); if( rc==SQLITE_DONE ) break; if( g.iTrace ) logMessage("begin %s (%d)", zTaskName, taskId); runScript(iClient, taskId, zScript, zTaskName); if( g.iTrace ) logMessage("end %s (%d)", zTaskName, taskId); finishScript(iClient, taskId, 0); sqlite3_free(zTaskName); sqlite3_sleep(10); } if( g.iTrace ) logMessage("end-client"); }else{ sqlite3_stmt *pStmt; int iTimeout; if( n==0 ){ fatalError("missing script filename"); } if( n>1 ) unrecognizedArguments(argv[0], n, argv+2); runSql( "DROP TABLE IF EXISTS task;\n" "DROP TABLE IF EXISTS counters;\n" "DROP TABLE IF EXISTS client;\n" "CREATE TABLE task(\n" " id INTEGER PRIMARY KEY,\n" " name TEXT,\n" " client INTEGER,\n" " starttime DATE,\n" " endtime DATE,\n" " script TEXT\n" ");" "CREATE INDEX task_i1 ON task(client, starttime);\n" "CREATE INDEX task_i2 ON task(client, endtime);\n" "CREATE TABLE counters(nError,nTest);\n" "INSERT INTO counters VALUES(0,0);\n" "CREATE TABLE client(id INTEGER PRIMARY KEY, wantHalt);\n" ); zScript = readFile(argv[2]); for(iRep=1; iRep<=nRep; iRep++){ if( g.iTrace ) logMessage("begin script [%s] cycle %d\n", argv[2], iRep); runScript(0, 0, zScript, argv[2]); if( g.iTrace ) logMessage("end script [%s] cycle %d\n", argv[2], iRep); } sqlite3_free(zScript); waitForClient(0, 2000, "during shutdown...\n"); trySql("UPDATE client SET wantHalt=1"); sqlite3_sleep(10); g.iTimeout = 0; iTimeout = 1000; while( ((rc = trySql("SELECT 1 FROM client"))==SQLITE_BUSY || rc==SQLITE_ROW) && iTimeout>0 ){ sqlite3_sleep(10); iTimeout -= 10; } sqlite3_sleep(100); pStmt = prepareSql("SELECT nError, nTest FROM counters"); iTimeout = 1000; while( (rc = sqlite3_step(pStmt))==SQLITE_BUSY && iTimeout>0 ){ sqlite3_sleep(10); iTimeout -= 10; } if( rc==SQLITE_ROW ){ g.nError += sqlite3_column_int(pStmt, 0); g.nTest += sqlite3_column_int(pStmt, 1); } sqlite3_finalize(pStmt); } sqlite3_close(g.db); maybeClose(g.pLog); maybeClose(g.pErrLog); if( iClient==0 ){ printf("Summary: %d errors out of %d tests\n", g.nError, g.nTest); printf("END: %s", argv[0]); for(i=1; i<argc; i++) printf(" %s", argv[i]); printf("\n"); } return g.nError>0; }