Esempio n. 1
0
// Overrides the function from QSyntaxHighlighter;
// gets called by QTextEditor whenever
// a block (line of text) needs to be repainted
void XHTMLHighlighter::highlightBlock(const QString &text)
{
    // By default, all block states are -1;
    // in our implementation regular text is state == 1
    if (previousBlockState() == -1) {
        setCurrentBlockState(State_Text);
    }
    // Propagate previous state; needed for state tracking
    else {
        setCurrentBlockState(previousBlockState());
    }

    if (text.isEmpty()) {
        return;
    }

    SettingsStore settings;
    m_enableSpellCheck = settings.spellCheck();

    // Run spell check over the text.
    if (m_enableSpellCheck && m_checkSpelling) {
        CheckSpelling(text);
    }

    // The order of these operations is important
    // because some states format text over previous states!
    HighlightLine(text, State_Entity);
    HighlightLine(text, State_CSS);
    HighlightLine(text, State_HTML);
    HighlightLine(text, State_CSSComment);
    HighlightLine(text, State_HTMLComment);
    HighlightLine(text, State_DOCTYPE);
}
Esempio n. 2
0
void PluginWidget::readSettings()
{
    SettingsStore settings;
    // The last folder used for saving and opening files
    m_LastFolderOpen = settings.pluginLastFolder();
    
    // Load the available plugin information
    PluginDB *pdb = PluginDB::instance();
    QHash<QString, Plugin *> plugins;
    int nrows = 0;

    ui.editPathPy2->setText(pdb->get_engine_path("python2.7"));
    ui.editPathPy3->setText(pdb->get_engine_path("python3.4"));

    // clear out the table but do NOT clear out column headings
    while (ui.pluginTable->rowCount() > 0) {
        ui.pluginTable->removeRow(0);
    }

    plugins = pdb->all_plugins();
    foreach(Plugin *p, plugins) {
        ui.pluginTable->insertRow(nrows);
        setPluginTableRow(p,nrows);
        nrows++;
    }
Esempio n. 3
0
PreferencesWidget::ResultAction GeneralSettingsWidget::saveSettings()
{

    int new_clean_on_level = 0;
    QString new_epub_version = "2.0";

    if (ui.EpubVersion3->isChecked()) {
        new_epub_version = "3.0";
    }
    if (ui.MendOnOpen->isChecked()) {
        new_clean_on_level |= CLEANON_OPEN;
    }
    if (ui.MendOnSave->isChecked()) {
        new_clean_on_level |= CLEANON_SAVE;
    }

    int new_remote_on_level = 0;

    if (ui.AllowRemote->isChecked()) {
        new_remote_on_level = 1;
    }

    SettingsStore settings;
    settings.setCleanOn(new_clean_on_level);
    settings.setDefaultVersion(new_epub_version);
    settings.setRemoteOn(new_remote_on_level);
    return PreferencesWidget::ResultAction_None;
}
Esempio n. 4
0
BookViewPreview::BookViewPreview(QWidget *parent)
    : QWebView(parent),
      c_GetBlock(Utility::ReadUnicodeTextFile(":/javascript/get_block.js")),
      m_isLoadFinished(false),
      m_ContextMenu(new QMenu(this)),
      m_ViewWebPage(new ViewWebPage(this)),
      c_jQuery(Utility::ReadUnicodeTextFile(":/javascript/jquery-1.6.2.min.js")),
      c_jQueryScrollTo(Utility::ReadUnicodeTextFile(":/javascript/jquery.scrollTo-1.4.2-min.js")),
      c_jQueryWrapSelection(Utility::ReadUnicodeTextFile(":/javascript/jquery.wrapSelection.js")),
      c_GetCaretLocation(Utility::ReadUnicodeTextFile(":/javascript/book_view_current_location.js")),
      c_GetRange(Utility::ReadUnicodeTextFile(":/javascript/get_range.js")),
      c_NewSelection(Utility::ReadUnicodeTextFile(":/javascript/new_selection.js")),
      c_GetParentTags(Utility::ReadUnicodeTextFile(":/javascript/get_parent_tags.js")),
      m_CaretLocationUpdate(QString()),
      m_pendingLoadCount(0),
      m_pendingScrollToFragment(QString())
{
    setContextMenuPolicy(Qt::CustomContextMenu);
    // Set the Zoom factor but be sure no signals are set because of this.
    SettingsStore settings;
    SetCurrentZoomFactor(settings.zoomPreview());
    // use our web page that can be used for debugging javascript
    setPage(m_ViewWebPage);
    // Enable our link filter.
    page()->setLinkDelegationPolicy(QWebPage::DelegateAllLinks);
    page()->settings()->setAttribute(QWebSettings::DeveloperExtrasEnabled, true);
    CreateContextMenuActions();
    ConnectSignalsToSlots();
}
Esempio n. 5
0
void PreviewWindow::LoadSettings()
{
    SettingsStore settings;
    settings.beginGroup(SETTINGS_GROUP);
    m_Splitter->restoreState(settings.value("splitter").toByteArray());
    settings.endGroup();
}
Esempio n. 6
0
SpellCheck::SpellCheck() :
    m_hunspell(0),
    m_codec(0),
    m_wordchars("")
{
    // There is a considerable lag involved in loading the Spellcheck dictionaries
    QApplication::setOverrideCursor(Qt::WaitCursor);
    loadDictionaryNames();
    // Create the user dictionary word list directiory if necessary.
    const QString user_directory = userDictionaryDirectory();
    QDir userDir(user_directory);

    if (!userDir.exists()) {
        userDir.mkpath(user_directory);
    }

    // Create the configured file if necessary.
    QFile userFile(currentUserDictionaryFile());

    if (!userFile.exists()) {
        if (userFile.open(QIODevice::WriteOnly)) {
            userFile.close();
        }
    }

    // Load the dictionary the user has selected if one was saved.
    SettingsStore settings;
    setDictionary(settings.dictionary());
    QApplication::restoreOverrideCursor();
}
Esempio n. 7
0
// Performs general cleaning (and improving)
// of provided book XHTML source code
QString CleanSource::Clean(const QString &source)
{
    SettingsStore settings;
    SettingsStore::CleanLevel level = settings.cleanLevel();
    QString newsource = PreprocessSpecialCases(source);

    switch (level) {
        case SettingsStore::CleanLevel_PrettyPrint:
        case SettingsStore::CleanLevel_PrettyPrintTidy: {
            newsource = level == SettingsStore::CleanLevel_PrettyPrint ? PrettyPrint(newsource) : PrettyPrintTidy(newsource);
            // Remove any empty comments left over from pretty printing.
            QStringList css_style_tags  = CSSStyleTags(newsource);
            css_style_tags = RemoveEmptyComments(css_style_tags);
            return WriteNewCSSStyleTags(newsource, css_style_tags);
        }
        case SettingsStore::CleanLevel_Tidy: {
            // We store the number of CSS style tags before
            // running Tidy so CleanCSS can remove redundant classes
            // if tidy added a new style tag
            int old_num_styles = RobustCSSStyleTagCount(newsource);
            newsource = HTMLTidy(newsource, Tidy_Clean);
            newsource = CleanCSS(newsource, old_num_styles);
            return newsource;
        }
        default:
            // The only thing we will do for Clean when set to None is just prettify
            // the XML declaration at the top. Xerces puts the xml, DOCTYPE and opening
            // html tag all on the same line which is ugly to read.
            return PrettifyDOCTYPEHeader(source);
    }
}
Esempio n. 8
0
void MetaEditor::WriteSettings()
{
    SettingsStore settings;
    settings.beginGroup(SETTINGS_GROUP);
    // The size of the window and it's full screen status
    settings.setValue("geometry", saveGeometry());
    settings.endGroup();
}
Esempio n. 9
0
void BookViewPreview::SetZoomFactor(float factor)
{
    SettingsStore settings;
    settings.setZoomPreview(factor);
    SetCurrentZoomFactor(factor);
    Zoom();
    emit ZoomFactorChanged(factor);
}
Esempio n. 10
0
void PreviewWindow::SplitterMoved(int pos, int index)
{
    Q_UNUSED(pos);
    Q_UNUSED(index);
    SettingsStore settings;
    settings.beginGroup(SETTINGS_GROUP);
    settings.setValue("splitter", m_Splitter->saveState());
    settings.endGroup();
}
Esempio n. 11
0
// Constructor;
// The parameter is the file to be imported
ImportHTML::ImportHTML(const QString &fullfilepath)
    :
    Importer(fullfilepath),
    m_IgnoreDuplicates(false),
    m_CachedSource(QString())
{
    SettingsStore ss;
    m_EpubVersion = ss.defaultVersion();
}
Esempio n. 12
0
QString CleanSource::CharToEntity(const QString &source)
{
    SettingsStore settings;
    QString new_source = source;
    QList<std::pair <ushort, QString>> codenames = settings.preserveEntityCodeNames();
    std::pair <ushort, QString> epair;
    foreach(epair, codenames) {
        new_source.replace(QChar(epair.first), epair.second);
    }
Esempio n. 13
0
void FindReplace::WriteSettingsVisible(bool visible)
{
    SettingsStore *settings = new SettingsStore();
    settings->beginGroup( SETTINGS_GROUP );

    settings->setValue( "visible", visible);

    settings->endGroup();
}
Esempio n. 14
0
void ImageTab::SetZoomFactor( float new_zoom_factor )
{
    // Save the zoom for this type.
    SettingsStore settings;
    settings.setZoomImage(new_zoom_factor);
    m_CurrentZoomFactor = new_zoom_factor;

    Zoom();
    emit ZoomFactorChanged( m_CurrentZoomFactor );
}
Esempio n. 15
0
void ImageTab::UpdateDisplay()
{
    SettingsStore settings;
    float stored_factor = settings.zoomImage();
    if ( stored_factor != m_CurrentZoomFactor )
    {
        m_CurrentZoomFactor = stored_factor;
        Zoom();
    }
}
Esempio n. 16
0
void BookViewPreview::UpdateDisplay()
{
    SettingsStore settings;
    float stored_factor = settings.zoomWeb();

    if (stored_factor != m_CurrentZoomFactor) {
        m_CurrentZoomFactor = stored_factor;
        Zoom();
    }
}
Esempio n. 17
0
void CleanSourceWidget::readSettings()
{
    SettingsStore settings;
    SettingsStore::CleanLevel level = settings.cleanLevel();
    ui.CleanLevelPrettyPrintGumbo->setChecked(level == SettingsStore::CleanLevel_PrettyPrintGumbo);
    ui.CleanLevelGumbo->setChecked(level == SettingsStore::CleanLevel_Gumbo);
    int cleanOn = settings.cleanOn();
    ui.CleanOnOpen->setChecked(cleanOn & CLEANON_OPEN);
    ui.CleanOnSave->setChecked(cleanOn & CLEANON_SAVE);
}
Esempio n. 18
0
void NCXResource::FillWithDefaultText()
{
    SettingsStore ss;
    QString version = ss.defaultVersion();
    if (version.startsWith('2')) {
        SetText(TEMPLATE_TEXT.arg(tr("Start")).arg(FIRST_SECTION_NAME));
      } else {
        SetText(TEMPLATE3_TEXT.arg(tr("Start")).arg(FIRST_SECTION_NAME));
      }
}
Esempio n. 19
0
QString UniversalUpdates::LoadAndUpdateOneHTMLFile(HTMLResource *html_resource,
        const QHash<QString, QString> &html_updates,
        const QHash<QString, QString> &css_updates,
        const QList<XMLResource *> &non_well_formed)
{
    SettingsStore ss;
    QString source;

    if (!html_resource) {
        return QString();
    }

    QString currentpath = html_resource->GetCurrentBookRelPath();
    QString version = html_resource->GetEpubVersion();

    // non_well_formed will only be set if the user has chosen not to have
    // the file auto fixed.
    if (non_well_formed.contains(html_resource)) {
        return QString("%1: %2").arg(NON_WELL_FORMED_MESSAGE).arg(html_resource->Filename());
    }

    try {
        source = XhtmlDoc::ResolveCustomEntities(html_resource->GetText());
        source = CleanSource::CharToEntity(source);

        if (ss.cleanOn() & CLEANON_OPEN) {
            source = CleanSource::Mend(source, version);
        }
        // Even though well formed checks might have already run we need to double check because cleaning might
        // have tried to fix and may have failed or the user may have said to skip cleanning.
        if (!XhtmlDoc::IsDataWellFormed(source)) {
            throw QObject::tr(NON_WELL_FORMED_MESSAGE);
        }

        source = PerformHTMLUpdates(source, html_updates, css_updates, currentpath, version)();
        html_resource->SetCurrentBookRelPath("");
        // For files that are valid we need to do a second clean becasue PerformHTMLUpdates) will remove
        // the formatting.
        if (ss.cleanOn() & CLEANON_OPEN) {
            source = CleanSource::Mend(source, version);
        }
        html_resource->SetText(source);
        return QString();
    } catch (ErrorBuildingDOM) {
        // It would be great if we could just let this exception bubble up,
        // but we can't since QtConcurrent doesn't let exceptions cross threads.
        // So we just leave the old source in the resource.
        return QString(QObject::tr("Invalid HTML file: %1")).arg(html_resource->Filename());
    } catch (QString err) {
        return QString("%1: %2").arg(err).arg(html_resource->Filename());
    } catch (...) {
        return QString("Cannot perform HTML updates there was an unrecoverable error: %1").arg(html_resource->Filename());
    }
}
Esempio n. 20
0
void AppearanceWidget::resetAllButtonClicked()
{
    SettingsStore settings;
    settings.clearAppearanceSettings();
    // Read and apply the settings without changing our m_codeViewAppearance
    // instance holding the last persisted values.
    SettingsStore::CodeViewAppearance codeViewAppearance = readSettings();
    ui.codeViewColorsList->blockSignals(true);
    loadCodeViewColorsList(codeViewAppearance);
    ui.codeViewColorsList->blockSignals(false);
}
Esempio n. 21
0
PluginDB::PluginDB()
{
    SettingsStore ss;

    m_engine_paths = ss.pluginEnginePaths();

    QDir pluginDir(pluginsPath());
    if (!pluginDir.exists()) {
        pluginDir.mkpath(pluginsPath());
    }
}
Esempio n. 22
0
void MetaEditor::ReadSettings()
{
    SettingsStore settings;
    settings.beginGroup(SETTINGS_GROUP);
    // The size of the window and it's full screen status
    QByteArray geometry = settings.value("geometry").toByteArray();

    if (!geometry.isNull()) {
        restoreGeometry(geometry);
    }
    settings.endGroup();
}
Esempio n. 23
0
void GeneralSettingsWidget::readSettings()
{
    SettingsStore settings;
    QString version = settings.defaultVersion();
    ui.EpubVersion2->setChecked(version == "2.0");
    ui.EpubVersion3->setChecked(version == "3.0");
    int cleanOn = settings.cleanOn();
    ui.MendOnOpen->setChecked(cleanOn & CLEANON_OPEN);
    ui.MendOnSave->setChecked(cleanOn & CLEANON_SAVE);
    int remoteOn = settings.remoteOn();
    ui.AllowRemote->setChecked(remoteOn);
}
Esempio n. 24
0
void EditTOC::ReadSettings()
{
    SettingsStore settings;
    settings.beginGroup(SETTINGS_GROUP);
    // The size of the window and it's full screen status
    QByteArray geometry = settings.value("geometry").toByteArray();

    if (!geometry.isNull()) {
        restoreGeometry(geometry);
    }

    // Column widths
    int size = settings.beginReadArray("column_data");

    for (int column = 0; column < size && column < ui.TOCTree->header()->count(); column++) {
        settings.setArrayIndex(column);
        int column_width = settings.value("width").toInt();

        if (column_width) {
            ui.TOCTree->setColumnWidth(column, column_width);
        }
    }
    settings.endArray();

    settings.endGroup();
}
Esempio n. 25
0
NavProcessor::NavProcessor(HTMLResource * nav_resource)
  : m_NavResource(nav_resource)
{
      bool valid = true;
      {
          QReadLocker locker(&m_NavResource->GetLock());
          QString source = m_NavResource->GetText();
          GumboInterface gi = GumboInterface(source, "3.0");
          gi.parse();
          const QList<GumboNode*> nav_nodes = gi.get_all_nodes_with_tag(GUMBO_TAG_NAV);
          valid = valid && nav_nodes.length() > 0;
          bool has_toc = false;
          for (int i = 0; i < nav_nodes.length(); ++i) {
              GumboNode* node = nav_nodes.at(i);
              GumboAttribute* attr = gumbo_get_attribute(&node->v.element.attributes, "epub:type");
              if (attr) {
                  QString etype = QString::fromUtf8(attr->value);
                  if (etype == "toc") has_toc = true;
              }
          }
          valid = valid && has_toc;
      }
      if (!valid) {
          SettingsStore ss;
          QString lang = ss.defaultMetadataLang();
          QString newsource = 
            "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n"
            "<!DOCTYPE html>\n"
            "<html xmlns=\"http://www.w3.org/1999/xhtml\" xmlns:epub=\"http://www.idpf.org/2007/ops\" "
            "lang=\"%1\" xml:lang=\"%2\">\n"
            "<head>\n"
            "  <meta charset=\"utf-8\" />\n"
            "  <style type=\"text/css\">\n"
            "    nav#landmarks, nav#page-list { display:none; }\n"
            "    ol { list-style-type: none; }\n"
            "  </style>\n"
            "</head>\n"
            "<body epub:type=\"frontmatter\">\n"
            "  <nav epub:type=\"toc\" id=\"toc\">\n"
            "  </nav>\n"
            "  <nav epub:type=\"landmarks\" id=\"landmarks\" hidden=\"\">\n"
            "  </nav>\n"
            "</body>\n"
            "</html>";
          newsource = newsource.arg(lang).arg(lang);
          QWriteLocker locker(&m_NavResource->GetLock());
          m_NavResource->SetText(newsource);
    }
}
Esempio n. 26
0
const QString OpenExternally::editorForResourceType(const Resource::ResourceType type)
{
    if (mayOpen(type)) {
        SettingsStore settings;
        settings.beginGroup(SETTINGS_GROUP);
        const QString &editorKey = QString("editor_") + RESOURCE_TYPE_NAME(type);

        if (settings.contains(editorKey)) {
            const QString &editorPath = settings.value(editorKey).toString();
            return QFile::exists(editorPath) ? editorPath : EMPTY;
        }
    }

    return EMPTY;
}
Esempio n. 27
0
SettingsStore::CodeViewAppearance AppearanceWidget::readSettings()
{
    SettingsStore settings;
    SettingsStore::BookViewAppearance bookViewAppearance = settings.bookViewAppearance();
    SettingsStore::CodeViewAppearance codeViewAppearance = settings.codeViewAppearance();
    SettingsStore::SpecialCharacterAppearance specialCharacterAppearance = settings.specialCharacterAppearance();
    loadComboValueOrDefault(ui.cbBookViewFontStandard,  bookViewAppearance.font_family_standard,    "Arial");
    loadComboValueOrDefault(ui.cbBookViewFontSerif,     bookViewAppearance.font_family_serif,       "Times New Roman");
    loadComboValueOrDefault(ui.cbBookViewFontSansSerif, bookViewAppearance.font_family_sans_serif,  "Arial");
    loadComboValueOrDefault(ui.cbCodeViewFont,          codeViewAppearance.font_family,             "Consolas");
    loadComboValueOrDefault(ui.cbSpecialCharacterFont,  specialCharacterAppearance.font_family,     "Helvetica");
    ui.bookViewFontSizeSpin->setValue(bookViewAppearance.font_size);
    ui.codeViewFontSizeSpin->setValue(codeViewAppearance.font_size);
    ui.specialCharacterFontSizeSpin->setValue(specialCharacterAppearance.font_size);
    codeViewAppearance.font_family = ui.cbCodeViewFont->currentText();
    return codeViewAppearance;
}
Esempio n. 28
0
void FindReplace::ShowHide()
{
    SettingsStore settings;
    settings.beginGroup( SETTINGS_GROUP );

    QVariant show_find_replace = settings.value( "visible" );

    settings.endGroup();

    // Hide the window by default
    if (show_find_replace.isNull() ? false : show_find_replace.toBool()) {
        show();
    }
    else {
        hide();
    }

}
Esempio n. 29
0
void UpdateChecker::ReplyRecieved( QNetworkReply* reply )
{
    Q_ASSERT( reply );

    SettingsStore settings;
    settings.beginGroup( SETTINGS_GROUP );

    QString last_online_version    = settings.value( LAST_ONLINE_VERSION_KEY, QString() ).toString();
    QString current_online_version = ReadOnlineVersion( TextInReply( reply ) );

    bool is_newer = IsOnlineVersionNewer( SIGIL_VERSION, current_online_version );

    // The message box is displayed only if the online version is newer
    // and only if the user hasn't been informed about this release before
    if ( is_newer && ( current_online_version != last_online_version ) )
    {
        QMessageBox::StandardButton button_clicked;

        button_clicked = QMessageBox::question( 
            0,
            QObject::tr( "Sigil" ),
            QObject::tr( "<p>A newer version of Sigil is available, version <b>%1</b>.<br/>"
                "The ChangeLog can be seen <a href='http://sigil.googlecode.com/git/ChangeLog.txt'>here</a>.</p>"
                "<p>Would you like to go to the download page?</p>" )
            .arg( current_online_version ),
            QMessageBox::Yes | QMessageBox::No,
            QMessageBox::Yes );

        if ( button_clicked == QMessageBox::Yes )
        
            QDesktopServices::openUrl( QUrl( DOWNLOAD_PAGE_LOCATION ) );        
    }

    // Store the current online version as the last one checked
    settings.setValue( LAST_ONLINE_VERSION_KEY, current_online_version );

    settings.endGroup();

    // Schedule this object for deletion.
    // There is no point for its existence
    // after it has received and processed the net reply. 
    deleteLater();
}
Esempio n. 30
0
// Loads the source code into the Book
QString ImportHTML::LoadSource()
{
    SettingsStore ss;

    if (m_CachedSource.isNull()) {
        if (!Utility::IsFileReadable(m_FullFilePath)) {
            throw (CannotReadFile(m_FullFilePath.toStdString()));
        }

        m_CachedSource = HTMLEncodingResolver::ReadHTMLFile(m_FullFilePath);
        m_CachedSource = CleanSource::CharToEntity(m_CachedSource);

        if (ss.cleanOn() & CLEANON_OPEN) {
            m_CachedSource = CleanSource::Clean(XhtmlDoc::ResolveCustomEntities(m_CachedSource));
        }
    }

    return m_CachedSource;
}