void ModuleUploader::init() { Core *core = Core::instance(); if (core->checkCmdLineOption(_optUpload) == true && _ignoreCmdParam == false) { UploaderConfig config; QString selectedtHost = config.loadSingleParam(QByteArray("common"), QByteArray(KEY_DEFAULT_HOST)).toString(); Uploader *uploader = 0; switch(config.labelsList().indexOf(selectedtHost)) { case 0: uploader = new Uploader_ImgUr; break; default: uploader = new Uploader_ImgUr; } connect(uploader, &Uploader::uploadDoneStr, this, &ModuleUploader::shadowUploadDone); connect(uploader, &Uploader::uploadFail, this, &ModuleUploader::shadowUploadFail); uploader->startUploading(); _ignoreCmdParam = true; } else { DialogUploader *ui = new DialogUploader(); ui->exec(); } }
void UploaderConfigWidget::loadSettings() { qDebug() << "load uploder common settings"; UploaderConfig config; QVariantMap loadValues; loadValues.insert("autoCopyDirectLink", QVariant(false)); loadValues.insert(KEY_DEFAULT_HOST, ""); loadValues = config.loadSettings("common", loadValues); QString defaultHost = loadValues[KEY_DEFAULT_HOST].toString(); if (defaultHost.isEmpty() == true) { _ui->cbxDefaultHost->setCurrentIndex(0); } else { qint8 index = config.labelsList().indexOf(defaultHost); if (index == -1) { index++; } _ui->cbxDefaultHost->setCurrentIndex(index); } _ui->checkAutoCopyMainLink->setChecked(loadValues["autoCopyDirectLink"].toBool()); }
void UploaderConfigWidget::saveSettings() { UploaderConfig config; QVariantMap savingValues; savingValues.insert(KEY_AUTO_COPY_RESULT_LIMK, _ui->checkAutoCopyMainLink->isChecked()); QString defaultHost = config.labelsList().at(_ui->cbxDefaultHost->currentIndex()); savingValues.insert(KEY_DEFAULT_HOST, defaultHost); config.saveSettings("common", savingValues); QMetaObject::invokeMethod(_imgur, "saveSettings"); }
DialogUploader::DialogUploader(QWidget *parent) : QDialog(parent), _ui(new Ui::DialogUploader) { _ui->setupUi(this); _ui->stackedWidget->setCurrentIndex(0); _uploader = 0; _uploaderWidget = 0; slotSeletHost(0); _ui->cbxUploaderList->addItems(UploaderConfig::labelsList()); UploaderConfig config; QString defaultHost = config.loadSingleParam(QByteArray("common"), QByteArray(KEY_DEFAULT_HOST)).toString(); if (defaultHost.isEmpty()) _selectedHost = 0; else { _selectedHost = config.labelsList().indexOf(defaultHost); if (_selectedHost == -1) _selectedHost = 0; } // load ishot preview QSize imgSize = Core::instance()->getPixmap()->size(); QString pixmapSize = tr("Size: ") + QString::number(imgSize.width()) + "x" + QString::number(imgSize.height()) + tr(" pixel"); _ui->labImgSize->setText(pixmapSize); _ui->labImage->setFixedWidth(256); _ui->labImage->setFixedHeight(192); _ui->labImage->setPixmap(Core::instance()->getPixmap()->scaled(_ui->labImage->size(), Qt::KeepAspectRatio, Qt::SmoothTransformation)); // progressbar _ui->progressBar->setVisible(false); _ui->progressBar->setFormat(tr("Uploaded ") + "%p%" + " (" + "%v" + " of " + "%m bytes"); // upload staus labelsList _ui->labUploadStatus->setText(tr("Ready to upload")); connect(_ui->butClose, &QPushButton::clicked, this, &DialogUploader::close); connect(_ui->butUpload, &QPushButton::clicked, this, &DialogUploader::slotUploadStart); void (QComboBox::*uploaderChnage)(int) = &QComboBox::currentIndexChanged; connect(_ui->cbxUploaderList, uploaderChnage, this, &DialogUploader::slotSeletHost); _ui->cbxUploaderList->setCurrentIndex(_selectedHost); }