int main(int argc, char *argv[]) { QApplication a(argc, argv); //禁止双开 HANDLE hObject = CreateMutex(NULL, FALSE, "SMonitorServer.exe"); if(ERROR_ALREADY_EXISTS == GetLastError()) { CloseHandle(hObject); QMessageBox::warning(NULL, QString::fromLocal8Bit("警告"), QString::fromLocal8Bit("服务器已经启动")); return 0; } if(!loadSocket()) { QMessageBox::information(NULL, "error", QString::fromLocal8Bit("加载SOCKET库失败, 服务器启动失败")); return 0; } //读取配置文件 readConfigure(); //启动服务器业务日志管理器 QString dataPath = QApplication::applicationDirPath() + "/ServerLogger/SvrLog"; QDir dir; if(!dir.mkpath(dataPath)) { QMessageBox::warning(NULL, "Error", QString::fromLocal8Bit("日志目录[%1]创建失败,请确认目标磁盘是否空间已满").arg(dataPath), QString::fromLocal8Bit("确定")); return false; } //dataPath = "d:/ServerLogger/SvrLog"; //yhb if(!ServerLogger->Start(dataPath.toLocal8Bit().constData())) { QMessageBox::information(NULL, "error", QString::fromLocal8Bit("加载服务器日志系统失败, 服务器启动失败")); return 0; } CLoginDialog dlg; if(dlg.exec() == QDialog::Rejected) { return 0; } //启动数据管理器线程 if(!CDataManagerThread::Instance()->Start()) { QMessageBox::information(NULL, "error", QString::fromLocal8Bit("数据管理器线程启动失败, 服务器启动失败")); return 0; } ServerLogger->AddLog("服务器软件运行"); CSMonitorServer w; w.show(); return a.exec(); }
OptionDlg::OptionDlg(QWidget *parent) : QDialog(parent) { readConfigure("etc/conf.xml"); readTargets("etc/targets.xml"); // 创建控件 tabWidget = new QTabWidget; tabGeneral = new QWidget; tabNetwork = new QWidget; tabTargets = new QWidget; tabWidget->addTab(tabGeneral, tr("General")); tabWidget->addTab(tabNetwork, tr("Network")); tabWidget->addTab(tabTargets, tr("Targets")); // tab general labelRecursiveLayer = new QLabel(tr("&Recursive layer:")); spinBoxRecursiveLayer = new QSpinBox(); spinBoxRecursiveLayer->setValue(recursiveLayer); labelRecursiveLayer->setBuddy(spinBoxRecursiveLayer); labelMinFileSize = new QLabel(tr("&Minimum file size(Kb):")); spinBoxMinFileSize = new QSpinBox(); spinBoxMinFileSize->setValue(minFileSize); labelMinFileSize->setBuddy(spinBoxMinFileSize); checkBoxSaveInSingleDir = new QCheckBox(tr("&Save targets in single directory")); checkBoxSaveInSingleDir->setChecked(saveInSingleDir); labelFileExistsAction = new QLabel(tr("&Do what when file exists:")); comboBoxFileExistsAction = new QComboBox(); comboBoxFileExistsAction->addItem(tr("Overwrite"), feaOverwrite); comboBoxFileExistsAction->addItem(tr("Ignore"), feaIgnore); comboBoxFileExistsAction->setCurrentIndex(fileExistsAction); labelFileExistsAction->setBuddy(comboBoxFileExistsAction); gridLayoutGeneral = new QGridLayout(); gridLayoutGeneral->addWidget(labelRecursiveLayer, 0, 0, 1, 1); gridLayoutGeneral->addWidget(spinBoxRecursiveLayer, 0, 1, 1, 1); gridLayoutGeneral->addWidget(labelMinFileSize, 1, 0, 1, 1); gridLayoutGeneral->addWidget(spinBoxMinFileSize, 1, 1, 1, 1); gridLayoutGeneral->addWidget(checkBoxSaveInSingleDir, 2, 0, 1, 2); gridLayoutGeneral->addWidget(labelFileExistsAction, 3, 0, 1, 1); gridLayoutGeneral->addWidget(comboBoxFileExistsAction, 3, 1, 1, 1); boxLayoutGeneral = new QVBoxLayout; boxLayoutGeneral->addLayout(gridLayoutGeneral); boxLayoutGeneral->addStretch(); tabGeneral->setLayout(boxLayoutGeneral); // tab Network checkBoxUseProxy = new QCheckBox(tr("&Enable proxy")); checkBoxUseProxy->setChecked(useProxy); connect(checkBoxUseProxy, SIGNAL(stateChanged(int)), this, SLOT(useProxyOrNot(int))); labelHost = new QLabel(tr("&Host:")); editHost = new QLineEdit(); editHost->setText(proxyHost); labelHost->setBuddy(editHost); labelPort = new QLabel(tr("&Port:")); spinBoxPort = new QSpinBox(); spinBoxPort->setMaximum(65535); spinBoxPort->setValue(proxyPort); labelPort->setBuddy(spinBoxPort); labelUsername = new QLabel(tr("&Username:"******"Pass&word:")); editPassword = new QLineEdit(); editPassword->setText(proxyPassword); editPassword->setEchoMode(QLineEdit::Password); labelPassword->setBuddy(editPassword); // 启用不启用代理 useProxyOrNot(checkBoxUseProxy->checkState()); gridLayoutNetwork = new QGridLayout(); gridLayoutNetwork->addWidget(checkBoxUseProxy, 0, 0, 1, 2); gridLayoutNetwork->addWidget(labelHost, 1, 0, 1, 1); gridLayoutNetwork->addWidget(editHost, 1, 1, 1, 1); gridLayoutNetwork->addWidget(labelPort, 2, 0, 1, 1); gridLayoutNetwork->addWidget(spinBoxPort, 2, 1, 1, 1); gridLayoutNetwork->addWidget(labelUsername, 3, 0, 1, 1); gridLayoutNetwork->addWidget(editUsername, 3, 1, 1, 1); gridLayoutNetwork->addWidget(labelPassword, 4, 0, 1, 1); gridLayoutNetwork->addWidget(editPassword, 4, 1, 1, 1); boxLayoutNetwork = new QVBoxLayout; boxLayoutNetwork->addLayout(gridLayoutNetwork); boxLayoutNetwork->addStretch(); tabNetwork->setLayout(boxLayoutNetwork); // tab targets boxLayoutTargets = new QVBoxLayout; int i = 1; foreach(Target target, targets) { QCheckBox *checkBoxTarget = new QCheckBox( QString("&%1. %2").arg(i).arg(target.desc)); if(target.selected) checkBoxTarget->setChecked(true); boxLayoutTargets->addWidget(checkBoxTarget); checkBoxTargets.push_back(checkBoxTarget); ++i; }