void KviIconWidget::init() { setWindowTitle(__tr2qs("Icon Table")); setWindowIcon(QIcon(*(g_pIconManager->getSmallIcon(KviIconManager::IconManager)))); int iRows = KviIconManager::IconCount / 20; if((iRows * 20) < KviIconManager::IconCount) iRows++; QGridLayout * pLayout = new QGridLayout(this); int i; for(i = 0; i < 20; i++) { KviCString szTmp(KviCString::Format,"%d",i); QLabel * pLabel = new QLabel(szTmp.ptr(),this); pLayout->addWidget(pLabel,0,i + 1); } for(i = 0; i < iRows; i++) { KviCString szTmp(KviCString::Format,"%d",i * 20); QLabel * pLabel = new QLabel(szTmp.ptr(),this); pLayout->addWidget(pLabel,i + 1,0); } for(i = 0; i < KviIconManager::IconCount; i++) { KviCString szTmp(KviCString::Format,"%d",i); QLabel * pLabel = new QLabel(this); pLabel->setObjectName(szTmp.ptr()); pLabel->setPixmap(*(g_pIconManager->getSmallIcon(i))); pLabel->installEventFilter(this); pLabel->setAcceptDrops(true); pLayout->addWidget(pLabel,(i / 20) + 1,(i % 20) + 1); } }
void KviWindow::preprocessMessage(QString & szMessage) { // FIXME: slow if(!m_pConsole || !m_pConsole->connection()) return; static QString szNonStandardLinkPrefix = QString::fromLatin1("\r!["); if(szMessage.contains(szNonStandardLinkPrefix)) return; // contains a non standard link that may contain spaces, do not break it. // FIXME: This STILL breaks $fmtlink() in certain configurations QStringList strings = szMessage.split(" "); for(auto & it : strings) { if(it.contains('\r')) continue; QString szTmp(it); szTmp = KviControlCodes::stripControlBytes(szTmp).trimmed(); if(szTmp.length() < 1) continue; if(m_pConsole->connection()->serverInfo()->supportedChannelTypes().contains(szTmp[0])) { if(it == szTmp) it = QString("\r!c\r%1\r").arg(it); else it = QString("\r!c%1\r%2\r").arg(szTmp, it); } } szMessage = strings.join(" "); }
void ScriptEditorWidget::loadCompleterFromFile() { QStringList szListFunctionsCommand; QString szTmp("kvscompleter.idx"); QString szPath; g_pApp->getLocalKvircDirectory(szPath,KviApplication::ConfigPlugins,szTmp); QString szBuffer; QFile f(szPath); f.open(QIODevice::ReadOnly); szBuffer = f.readAll(); f.close(); szListFunctionsCommand = szBuffer.split(','); createCompleter(szListFunctionsCommand); }
void ScriptEditorWidget::asyncCompleterCreation() { //static int iIndex = 0; //static int iModulesCount = 0; if(!iIndex) { m_pListCompletition = new QStringList(); QString szPath; g_pApp->getGlobalKvircDirectory(szPath,KviApplication::Modules); QDir d(szPath); #if defined(COMPILE_ON_WINDOWS) d.setNameFilters(QStringList("kvi*.dll")); #elif defined(COMPILE_ON_MINGW) d.setNameFilters(QStringList("libkvi*.dll")); #else d.setNameFilters(QStringList("libkvi*.so")); #endif m_pListModulesNames = new QStringList(d.entryList(QDir::Files | QDir::Readable)); iModulesCount = m_pListModulesNames->count(); } QString szModuleName = m_pListModulesNames->at(iIndex); iIndex++; #if defined(COMPILE_ON_WINDOWS) szModuleName=szModuleName.replace("kvi",""); szModuleName=szModuleName.replace(".dll",""); #elif defined(COMPILE_ON_MINGW) szModuleName=szModuleName.replace("libkvi",""); szModuleName=szModuleName.replace(".dll",""); #else szModuleName=szModuleName.replace("libkvi",""); szModuleName=szModuleName.replace(".so",""); #endif KviModule * pModule = g_pModuleManager->getModule(szModuleName); if(pModule) { pModule->getAllFunctionsCommandsModule(m_pListCompletition,szModuleName); } if(iIndex == iModulesCount) { m_pStartTimer->stop(); m_pStartTimer->deleteLater(); m_pStartTimer = 0; QString szTmp("kvscompleter.idx"); QString szPath; g_pApp->getLocalKvircDirectory(szPath,KviApplication::ConfigPlugins,szTmp); KviKvsKernel::instance()->getAllFunctionsCommandsCore(m_pListCompletition); QString szBuffer = m_pListCompletition->join(","); QFile f(szPath); f.open(QIODevice::WriteOnly); f.write(szBuffer.toUtf8()); f.close(); createCompleter(*m_pListCompletition); iIndex = 0; iModulesCount = 0; bCompleterReady=true; delete m_pListCompletition; delete m_pListModulesNames; } }
int main(int argc, char ** argv) { ParseArgs a; a.argc = argc; a.argv = argv; a.configFile = 0; a.createFile = false; a.bForceNewSession = false; a.bShowPopup = false, a.bShowSplashScreen = true; a.bExecuteCommandAndClose = false; int iRetCode = parseArgs(&a); if(iRetCode != KVI_ARGS_RETCODE_OK) { return ((iRetCode == KVI_ARGS_RETCODE_ERROR) ? (-1) : 0); } #ifdef COMPILE_KDE_SUPPORT #ifdef COMPILE_KDE4_SUPPORT // KDE4 KAboutData * pAboutData = new KAboutData( // FIXME: this is never deleted ? Should it be ? "kvirc", // internal program name "kvirc", // message catalogue name ki18n("KVIrc"), // user-visible program name KVI_VERSION, // program version ki18n("Visual IRC Client"), // description KAboutData::License_GPL, // license ki18n("(c) 1998-2015 The KVIrc Development Team"), ki18n("???"), // *some other text* ???? "http://www.kvirc.net", // homepage "https://github.com/kvirc/KVIrc/issues" // bug address (FIXME: this would be an E-MAIL address...) ); //fake argc/argv initialization: kde will use argv[0] as out appName in some dialogs // (eg: kdebase/workspace/kwin/killer/killer.cpp) KCmdLineArgs::init(1, &argv[0], pAboutData); #else //!COMPILE_KDE4_SUPPORT // KDE5 KAboutData * pAboutData = new KAboutData( // FIXME: this is never deleted ? Should it be ? "kvirc", // internal program name "KVIrc", // user-visible program name KVI_VERSION, // program version ki18n("Visual IRC Client").toString(), // description KAboutLicense::GPL, // license "(c) 1998-2015 The KVIrc Development Team", "???", // *some other text* ???? "http://www.kvirc.net", // homepage "https://github.com/kvirc/KVIrc/issues" // bug address (FIXME: this would be an E-MAIL address...) ); #endif //!COMPILE_KDE4_SUPPORT #endif KviApplication * pTheApp = new KviApplication(argc,argv); #ifdef COMPILE_KDE_SUPPORT #ifdef COMPILE_KDE4_SUPPORT pTheApp->setAboutData(pAboutData); #else KAboutData::setApplicationData(*pAboutData); delete pAboutData; #endif #endif #ifdef COMPILE_DBUS_SUPPORT #ifndef COMPILE_KDE_SUPPORT new KviDbusAdaptor(pTheApp); // FIXME: shouldn't this be deleted by someone ? QDBusConnection::sessionBus().registerObject("/MainApplication", pTheApp); #endif #endif QString szRemoteCommand = a.szExecCommand; if(!a.szExecRemoteCommand.isEmpty()) { if(!szRemoteCommand.isEmpty()) szRemoteCommand.append('\n'); szRemoteCommand.append(a.szExecRemoteCommand); } /* FIXME: There is a race condition in the IPC mechanism. If one starts two instances of kvirc one immediately after another then both instances may run through kvi_sendIpcMessage without finding the sentinel window and thus both may decide to start. A weak file locking mechanism should be used too... #if defined(COMPILE_ON_WINDOWS) || defined(COMPILE_ON_MINGW) QString szLock = convertSeparators(cleanDirPath(QDir::homePath() + "/.kvirc.lock")); #else QString szLock = convertSeparators(cleanDirPath(QDir::homePath() + "/.kvirc.lock")); #endif QFileInfo inf(szLock); bool bLocked = false; if(inf.exists()) { iLocked = inf.lastModified().secsTo(QDateTime::currentDateTime()); } */ #ifndef COMPILE_NO_IPC if(!a.bForceNewSession) { // here we could use CreateMutex on win and semget() on linux // in order to get a shared semaphore to ensure instance unicity. if(kvi_sendIpcMessage(szRemoteCommand.toLocal8Bit().data())) { if(szRemoteCommand.isEmpty()) { KviCString szTmp(KviCString::Format,"Another KVIrc session is already running on this display and with this user id.\nUse %s -f if you want to force a new session.",argv[0]); if(a.bShowPopup) { QMessageBox::information(0,"Session - KVIrc",szTmp.ptr(),QMessageBox::Ok); } else { qDebug("%s",szTmp.ptr()); } } delete pTheApp; return 0; } if(a.bExecuteCommandAndClose) { delete pTheApp; return 0; } } #endif pTheApp->m_bCreateConfig = a.createFile; pTheApp->m_szConfigFile = a.configFile; pTheApp->m_szExecAfterStartup = a.szExecCommand; pTheApp->m_bShowSplashScreen = a.bShowSplashScreen; pTheApp->setup(); // YEAH! int iRetVal = pTheApp->exec(); // :) delete pTheApp; return iRetVal; }
void WebFetcher::Parse(AirTicketTable &MyTable) { CString szTmp(pContent); const int HEAD_LEN = 12; const int TAIL_LEN = 2; int nStart = szTmp.Find("var cached=\"", 0); int nEnd = szTmp.Find("\";", nStart); nStart += HEAD_LEN; nEnd += TAIL_LEN; // 获得有效信息内容 szTmp = szTmp.Mid(nStart, nEnd - nStart); CString Date; CString FlightSn; UINT4 Price; CString Site; CString Url; CString DepartTime; CString ArriveTime; CString DepartAirport; CString ArriveAirport; CString Company; CString PlaneType; CString TimeStamp; // 分词列表 vector<CString> StrList; nStart = 0; int Split = szTmp.Find("\\t", nStart); // 没有机票信息 if (-1 == Split) { return; } // 分割机票信息 while (-1 != Split) { CString Str = szTmp.Mid(nStart, Split - nStart); // 发现换行,即下一条机票 if (-1 != Str.Find("\\n", 0)) { StrList.push_back(Str.Mid(0, Str.Find("\\n", 0))); StrList.push_back(Str.Mid(Str.Find("\\n", 0) + 2)); } else { StrList.push_back(Str); } nStart = Split + 2; Split = szTmp.Find("\\t", nStart); } StrList.push_back(szTmp.Mid(nStart, Split - nStart)); // 使用分词列表建立机票信息库 for (int i = 0; i < StrList.size(); i+= 12) { Date = StrList[i]; FlightSn = StrList[i + 1]; Price = atoi(StrList[i + 2]); Site = StrList[i + 3]; Url = StrList[i + 4]; // 如果使用相对网址 if (-1 == Url.Find("http://", 0)) { Url = "http://jipiao.kooxoo.com" + Url; } DepartTime = StrList[i + 5]; ArriveTime = StrList[i + 6]; DepartAirport = StrList[i + 7]; ArriveAirport = StrList[i + 8]; Company = StrList[i + 9]; PlaneType = StrList[i + 10]; TimeStamp = StrList[i + 11]; AirTicket MyTicket(Date, FlightSn, Price, Site, Url, DepartTime, ArriveTime, DepartAirport, ArriveAirport, Company, PlaneType, TimeStamp); MyTable.Add(MyTicket); } return; }
void ChangeList::dump( UInt32 uiIndent, const BitVector bvFlags ) const { ChangedStoreConstIt cIt = _createdStore.begin(); ChangedStoreConstIt cEnd = _createdStore.end (); fprintf(stderr, "CL created dump\n"); while(cIt != cEnd) { for(UInt32 i = 0; i < uiIndent + 4; ++i) { fprintf(stderr, " "); } fprintf(stderr, "CE : %u %u\n", (*cIt)->uiEntryDesc, (*cIt)->uiContainerId); ++cIt; } cIt = _changedStore.begin(); cEnd = _changedStore.end (); fprintf(stderr, "CL changed dump\n"); while(cIt != cEnd) { for(UInt32 i = 0; i < uiIndent + 4; ++i) { fprintf(stderr, " "); } FieldContainer *pTmp = FieldContainerFactory::the()->getContainer((*cIt)->uiContainerId); std::string szTmp("Unknown"); if(pTmp != NULL) { szTmp.assign(pTmp->getType().getCName()); } BitVector tmpChanges = 0xDEADBEEF; if((*cIt)->bvUncommittedChanges != NULL && pTmp != NULL) { tmpChanges = *((*cIt)->bvUncommittedChanges); } fprintf(stderr, "CE : %u %u 0x%016"PRIx64" 0x%016"PRIx64" (%p|%p) | %s\n", (*cIt)->uiEntryDesc, (*cIt)->uiContainerId, tmpChanges, (*cIt)->whichField, (*cIt), (*cIt)->bvUncommittedChanges, szTmp.c_str()); ++cIt; } cIt = _uncommitedChanges.begin(); cEnd = _uncommitedChanges.end (); fprintf(stderr, "CL uncommited dump\n"); while(cIt != cEnd) { for(UInt32 i = 0; i < uiIndent + 4; ++i) { fprintf(stderr, " "); } FieldContainer *pTmp = FieldContainerFactory::the()->getContainer((*cIt)->uiContainerId); std::string szTmp("Unknown"); if(pTmp != NULL) { szTmp.assign(pTmp->getType().getCName()); } BitVector tmpChanges = 0xDEADBEEF; if((*cIt)->bvUncommittedChanges != NULL && pTmp != NULL) { tmpChanges = *((*cIt)->bvUncommittedChanges); } fprintf(stderr, "CE : %u %u 0x%016"PRIx64" 0x%016"PRIx64" (%p|%p) | %s\n", (*cIt)->uiEntryDesc, (*cIt)->uiContainerId, tmpChanges, (*cIt)->whichField, (*cIt), (*cIt)->bvUncommittedChanges, szTmp.c_str()); ++cIt; } cIt = _workStore.begin(); cEnd = _workStore.end (); fprintf(stderr, "CL workstore dump\n"); while(cIt != cEnd) { for(UInt32 i = 0; i < uiIndent + 4; ++i) { fprintf(stderr, " "); } FieldContainer *pTmp = FieldContainerFactory::the()->getContainer((*cIt)->uiContainerId); BitVector tmpChanges = 0xDEADBEEF; if((*cIt)->bvUncommittedChanges != NULL && pTmp != NULL) { tmpChanges = *((*cIt)->bvUncommittedChanges); } fprintf(stderr, "CE : %u %u 0x%016"PRIx64" 0x%016"PRIx64"\n", (*cIt)->uiEntryDesc, (*cIt)->uiContainerId, tmpChanges, (*cIt)->whichField); ++cIt; } }