NewslineWidget::NewslineWidget(QWidget* Parent): QWidget(Parent),ui(new Ui::NewslineWidget) { ui->setupUi(this); ui->ContentsFrame->setStyleSheet(QString("QFrame#ContentsFrame { background-color : %1;}") .arg(BUILDER_NEWSLINE_BGCOLOR)); ui->NewslineLabel->setText(QString("<b><big>%1</big></b>").arg(tr("Newsline"))); ui->NewslineLabel->setStyleSheet(QString("color : %1;").arg(BUILDER_NEWSLINE_TEXTCOLOR)); ui->NoNewsLabel->setStyleSheet(QString("color : %1;").arg(BUILDER_NEWSLINE_TEXTCOLOR)); ui->NoNewsLabel->setVisible(false); ui->NewslineContents->setStyleSheet(QString("QWidget#NewslineContents { background-color : %1;}") .arg(BUILDER_NEWSLINE_BGCOLOR)); if (openfluid::base::PreferencesManager::instance()->getLang() != "default") NewsItemWidget::setLocale(QLocale(openfluid::base::PreferencesManager::instance()->getLang())); else NewsItemWidget::setLocale(QLocale(QLocale::English)); refreshFromCache(); // check if update is needed if (NewslineDownloadWorker::isTimeForDownload(NewsItemWidget::getLocale().name().left(2))) launchDownload(); connect(ui->UpdateButton,SIGNAL(clicked()),this,SLOT(launchDownload())); }
void MainWindow::onEditorChanged() { if (!refreshFromCache()) m_needsRefresh = true; setWindowModified(true); enableUndoRedoActions(); }
void MainWindow::refresh(bool forced) { if (m_process) { qDebug() << "still processing previous refresh. skipping..."; return; } if (!m_needsRefresh && !forced) { return; } if (!m_hasValidPaths) { qDebug() << "please configure paths for plantuml and java. aborting..."; statusBar()->showMessage(tr("PlantUML or Java not found. Please set them correctly in the \"Preferences\" dialog!")); return; } if (!forced && refreshFromCache()) { return; } QByteArray current_document = m_editor->toPlainText().toUtf8().trimmed(); if (current_document.isEmpty()) { qDebug() << "empty document. skipping..."; return; } m_needsRefresh = false; switch(m_currentImageFormat) { case SvgFormat: m_imageWidget->setMode(PreviewWidget::SvgMode); break; case PngFormat: m_imageWidget->setMode(PreviewWidget::PngMode); break; } QString key = makeKeyForDocument(current_document); statusBar()->showMessage(tr("Refreshing...")); QStringList arguments; arguments << "-jar" << m_plantUmlPath << QString("-t%1").arg(m_imageFormatNames[m_currentImageFormat]); if (m_useCustomGraphiz) { arguments << "-graphizdot" << m_graphizPath; } arguments << "-charset" << "UTF-8" << "-pipe"; m_lastKey = key; m_process = new QProcess(this); QFileInfo fi(m_documentPath); m_process->setWorkingDirectory(fi.absolutePath()); m_process->start(m_javaPath, arguments); if (!m_process->waitForStarted()) { qDebug() << "refresh subprocess failed to start"; return; } connect(m_process, SIGNAL(finished(int)), this, SLOT(refreshFinished())); m_process->write(current_document); m_process->closeWriteChannel(); }
void NewslineWidget::handleDowloadFinished() { ui->UpdateButton->setEnabled(true); refreshFromCache(); }