int getInput(int argc, char** argv){ /* extern int opt; extern int numberOfGenerations; extern char* inputPngFilename; extern char* outputPngFilename; extern char* programName; extern int userSetNumberOfGenerations; extern char *usage; */ numberOfGenerations = 50; inputPngFilename = NULL; outputPngFilename = NULL; programName = argv[0]; userSetNumberOfGenerations = 0; usage = "Usage:\n%s -i|-I input_file -o|-O output_file [-n|-N number_of_generations] [-h|-H] \n" "h- get help (see this menu)\n" "input_file- file of an input picture with .png extension \n" "output_file- name of a file to save the resulting picture to with .png extension \n" "number_of_generations- optional parameter, specifies the number of generation iterations, by default: 50 \n"; while ((opt = getopt(argc, argv, "n:N:i:I:o:O:"))!=-1){ switch(opt){ case 'n': case 'N': numberOfGenerations = atoi(optarg); printf("Number of generations = %d\n",numberOfGenerations); userSetNumberOfGenerations = 1; break; case 'i': case 'I': inputPngFilename = optarg; printf("Reading from a '%s' file\n", inputPngFilename); break; case 'o': case 'O': outputPngFilename = optarg; printf("Output file directory: %s\n", outputPngFilename); break; default: printf(usage, programName); exit (EXIT_FAILURE); } } if( optind < argc || inputPngFilename == NULL || outputPngFilename == NULL || argc < 2 || numberOfGenerations <= 0) { tellWhatsWrong(optind, numberOfGenerations, inputPngFilename, outputPngFilename, argc, argv); showHowToUse(usage, programName); exit (EXIT_FAILURE); } if (!userSetNumberOfGenerations) fprintf(stderr,"Assuming number of generations is a default value (50)\n"); return EXIT_SUCCESS; }
MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWindow) { settingsOpen = false; onSave = 0; QDir home(QDir::homePath()+"/parserYandex/"); QDir homeSaved(QDir::homePath()+"/parserYandex/saved/"); if (!home.exists()) home.mkpath(QDir::homePath()+"/parserYandex/"); if (!homeSaved.exists()) home.mkpath(QDir::homePath()+"/parserYandex/saved"); path = QDir::homePath()+"/parserYandex/saved/"; ui->setupUi(this); ui->settingsButton->setIcon(QIcon(":/icons/settings.png")); ui->settingsButton->setFixedSize(24,24); ui->settingsButton->setStyleSheet( "QPushButton {" "image: url(:/icons/settings.png); " "border: none;" "}" "QPushButton:hover {" "image: url(:/icons/settings_pressed.png);" "}" "QPushButton:pressed {" "image: url(:/icons/settings_pressed.png);" "}" "QPushButton:focus {" "border: none;" "}" ); ui->enterButton->setIcon(QIcon(":/icons/clear.png")); ui->enterButton->setFixedSize(20,20); ui->enterButton->setStyleSheet( "QPushButton {" "image: url(:/icons/clear.png); " "border: none;" "}" "QPushButton:hover {" "image: url(:/icons/clear_pressed.png);" "}" "QPushButton:pressed {" "image: url(:/icons/clear.png);" "}" "QPushButton:focus {" "border: none;" "}" ); this->resize(QSize(630,166)); ui->yandexBox->setChecked(true); ui->progressBar->hide(); ui->autoCompletion->hide(); ui->autoCompletion->setResizeMode(QListView::Adjust); ui->settings->hide(); ui->settings_arrow->hide(); ui->resultTable->hide(); ui->label->setText(QString("История пуста. Начни менять историю прямо сейчас.")); ui->newWindow->setShortcut(Qt::Key_Control+Qt::Key_N); ui->newWindow->setEnabled(true); ui->exit->setShortcuts(QKeySequence::Quit); manager = new QNetworkAccessManager(this); connect(ui->exit, SIGNAL(triggered()), qApp, SLOT(closeAllWindows())); connect(ui->newWindow, SIGNAL(triggered()), this, SLOT(newWindow())); connect(ui->searchString, SIGNAL(returnPressed()), this, SLOT(sendString())); connect(ui->settingsButton, SIGNAL(clicked()), this, SLOT(settingsButtonClicked())); connect(ui->enterButton, SIGNAL(clicked()), this, SLOT(clearString())); connect(ui->about, SIGNAL(triggered()), this, SLOT(showAuthor())); connect(ui->help, SIGNAL(triggered()), this, SLOT(showHowToUse())); connect(ui->searchString, SIGNAL(textEdited(QString)), this, SLOT(getAutoComplition(QString))); initTest(); }