コード例 #1
0
ファイル: pos.cpp プロジェクト: KDE/lokalize
bool switchPrev(Catalog*& catalog,DocPosition& pos,int parts)
{
    bool switchEntry=false;
    bool switchCommentIndex=false;
    if (pos.part==DocPosition::Comment)
        switchCommentIndex=true;
    else if (pos.part==DocPosition::Target)
    {
        if (parts&DocPosition::Source)
            pos.part=DocPosition::Source;
        switchEntry=!(parts&DocPosition::Source);
    }
    else if (pos.part==DocPosition::Source)
        switchEntry=true;

    bool skipCommentThisTime=false;
    if (switchCommentIndex)
    {
        if (pos.form)
            pos.form--;
        switchEntry=pos.form; //pos.form is zero again
        skipCommentThisTime=pos.form;
    }

    if (!switchEntry)
        return true;

    if (KDE_ISUNLIKELY( pos.form>0
                        && catalog->isPlural(pos.entry)))
        pos.form--;
    else if (KDE_ISUNLIKELY( pos.entry==0 ))
        return false;
    else
    {
        pos.entry--;
        pos.form=catalog->isPlural(pos.entry)*(catalog->numberOfPluralForms()-1);
    }
    pos.offset=0;

    if (parts&DocPosition::Comment && !skipCommentThisTime && pos.form==0 && catalog->notes(pos).size())
    {
        pos.part=DocPosition::Comment;
        pos.form=catalog->notes(pos).size()-1;
    }
    else
        pos.part=DocPosition::Target;

    return true;
}
コード例 #2
0
ファイル: pos.cpp プロジェクト: KDE/lokalize
bool switchNext(Catalog*& catalog,DocPosition& pos,int parts)
{
    bool switchEntry=false;
    bool switchCommentIndex=false;
    if (pos.part==DocPosition::Source)
        pos.part=DocPosition::Target;
    else if (pos.part==DocPosition::Target)
    {
        if (parts&DocPosition::Comment && pos.form==0 && catalog->notes(pos).size())
            pos.part=DocPosition::Comment;
        else
            switchEntry=true;
    }
    else if (pos.part==DocPosition::Comment)
        switchCommentIndex=true;

    if (switchCommentIndex)
    {
        pos.form++;
        if (catalog->notes(pos).size()==pos.form)
        {
            pos.form=0;
            switchEntry=true;
        }
    }

    if (!switchEntry)
        return true;


    if (KDE_ISUNLIKELY( pos.entry!=-1
                        && pos.form+1 < catalog->numberOfPluralForms()
                        && catalog->isPlural(pos.entry)))
        pos.form++;
    else if (KDE_ISUNLIKELY( pos.entry==catalog->numberOfEntries()-1 ))
        return false;
    else
    {
        pos.entry++;
        pos.form=0;
    }
    pos.offset=0;

    pos.part=(parts&DocPosition::Source)?DocPosition::Source:DocPosition::Target;

    return true;
}
コード例 #3
0
void MergeView::gotoNextChanged()
{
    if (KDE_ISUNLIKELY( !m_mergeCatalog ))
        return;

    DocPosition pos;

    //first, check if there any plural forms waiting to be synced
    int form=pluralFormsAvailableForward();
    if (KDE_ISUNLIKELY( form!=-1 ))
    {
        pos=m_pos;
        pos.form=form;
    }
    else if(KDE_ISUNLIKELY( (pos.entry=m_mergeCatalog->nextChangedIndex(m_pos.entry)) == -1 ))
        return;

    emit gotoEntry(pos,0);
}
コード例 #4
0
void MergeView::mergeAcceptAllForEmpty()
{
    if(KDE_ISUNLIKELY(!m_mergeCatalog)) return;

    bool update=m_mergeCatalog->changedEntries().contains(m_pos.entry);

    m_mergeCatalog->copyToBaseCatalog(/*MergeCatalog::EmptyOnly*/MergeCatalog::HigherOnly);

    if (update!=m_mergeCatalog->changedEntries().contains(m_pos.entry))
        emit gotoEntry(m_pos,0);
}
コード例 #5
0
void MergeView::gotoPrevChanged()
{
    if (KDE_ISUNLIKELY( !m_mergeCatalog ))
        return;

    DocPosition pos;

    //first, check if there any plural forms waiting to be synced
    int form=pluralFormsAvailableBackward();
    if (KDE_ISUNLIKELY( form!=-1 ))
    {
        pos=m_pos;
        pos.form=form;
    }
    else if(KDE_ISUNLIKELY( (pos.entry=m_mergeCatalog->prevChangedIndex(m_pos.entry)) == -1 ))
        return;

    if (KDE_ISUNLIKELY( m_mergeCatalog->isPlural(pos.entry)&&form==-1 ))
        pos.form=qMin(m_baseCatalog->numberOfPluralForms(),m_mergeCatalog->numberOfPluralForms())-1;

    emit gotoEntry(pos,0);
}
コード例 #6
0
ファイル: projectmodel.cpp プロジェクト: ShermanHuang/kdesdk
static KFileMetaInfo cachedMetaInfo(const KFileItem& file)
{
    QString dbName="metainfocache";
    if (!QSqlDatabase::contains(dbName))
    {
        QSqlDatabase db=QSqlDatabase::addDatabase("QSQLITE",dbName);
        db.setDatabaseName(KStandardDirs::locateLocal("appdata", dbName+".sqlite"));
        if (KDE_ISUNLIKELY( !db.open() ))
            return KFileMetaInfo(file.url());
        initDataBase(db);
    }
    QSqlDatabase db=QSqlDatabase::database(dbName);
    if (!db.isOpen())
        return KFileMetaInfo(file.url());

    static const QString fields[]={
        "translation.translated",
        "translation.untranslated",
        "translation.fuzzy",
        "translation.last_translator",
        "translation.source_date",
        "translation.translation_date",
        "translation.translated_reviewer",
        "translation.translated_approver",
        "translation.fuzzy_reviewer",
        "translation.fuzzy_approver"
    };
    static const int nFields = sizeof(fields) / sizeof(fields[0]);

    QByteArray result;

    QSqlQuery queryCache(db);
    queryCache.prepare("SELECT * from metainfo where filepath=?");
    queryCache.bindValue(0, qHash(file.localPath()));
    queryCache.exec();
    if (queryCache.next() && file.time(KFileItem::ModificationTime).dateTime()==queryCache.value(2).toDateTime())
    {
        result=queryCache.value(1).toByteArray();
        QDataStream stream(&result,QIODevice::ReadOnly);

        //unfortunately direct KFileMetaInfo << operator doesn't work
        KFileMetaInfo info;
        QVector<QVariant> keys;
        stream>>keys;
        for(int i=0;i<keys.count();i++)
            info.item(fields[i]).setValue(keys.at(i));
        return info;
    }
コード例 #7
0
void PoItemDelegate::paint (QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const
{
    if (index.column() != ProjectModel::Graph)
        return QStyledItemDelegate::paint(painter,option,index);

    QVariant graphData = index.data(Qt::DisplayRole);
    if (KDE_ISUNLIKELY( !graphData.isValid()))
    {
        painter->fillRect(option.rect,Qt::transparent);
        return;
    }

    QRect rect = graphData.toRect();
    int translated = rect.left();
    int untranslated = rect.top();
    int fuzzy = rect.width();
    int total = translated + untranslated + fuzzy;

    if (total > 0)
    {
        painter->setPen(Qt::white);
        QRect myRect(option.rect);
        myRect.setWidth(option.rect.width() * translated / total);
        painter->fillRect(myRect, m_colorScheme.foreground(KColorScheme::PositiveText));
        //painter->drawText(myRect,Qt::AlignRight,QString("%1").arg(data.left()));

        myRect.setLeft(myRect.left() + myRect.width());
        myRect.setWidth(option.rect.width() * fuzzy / total);
        painter->fillRect(myRect, m_colorScheme.foreground(KColorScheme::NeutralText));
        // painter->drawText(myRect,Qt::AlignRight,QString("%1").arg(data.width()));

        myRect.setLeft(myRect.left() + myRect.width());
        myRect.setWidth(option.rect.width() - myRect.left() + option.rect.left());
        painter->fillRect(myRect, m_colorScheme.foreground(KColorScheme::NegativeText));
        // painter->drawText(myRect,Qt::AlignRight,QString("%1").arg(data.top()));
    }
    else if (total == -1)
        painter->fillRect(option.rect,Qt::transparent);
    else if (total == 0)
        painter->fillRect(option.rect,QBrush(Qt::gray));
}
コード例 #8
0
void MergeView::mergeOpen(KUrl url)
{
    if (KDE_ISUNLIKELY( !m_baseCatalog->numberOfEntries() ))
        return;

    if (url==m_baseCatalog->url())
    {
        //(we are likely to be _mergeViewSecondary)
        //special handling: open corresponding file in the branch
        //for AutoSync

        QString path=QFileInfo(url.toLocalFile()).canonicalFilePath(); //bug 245546 regarding symlinks
        QString oldPath=path;
        path.replace(Project::instance()->poDir(),Project::instance()->branchDir());

        if (oldPath==path) //if file doesn't exist both are empty
        {
            cleanup();
            return;
        }

        url=KUrl(path);
    }

    if (url.isEmpty())
    {
        Project::instance()->model()->weaver()->suspend();
        url=KFileDialog::getOpenUrl(KUrl("kfiledialog:///merge-source") /*m_baseCatalog->url()*/ , "text/x-gettext-translation",this);
        Project::instance()->model()->weaver()->resume();
    }
    if (url.isEmpty())
        return;

    delete m_mergeCatalog;
    m_mergeCatalog=new MergeCatalog(this,m_baseCatalog);
    int errorLine=m_mergeCatalog->loadFromUrl(url);
    if (KDE_ISLIKELY( errorLine==0 ))
    {
        if (m_pos.entry>0)
            emit signalPriorChangedAvailable(m_pos.entry>m_mergeCatalog->firstChangedIndex());

        emit signalNextChangedAvailable(m_pos.entry<m_mergeCatalog->lastChangedIndex());

        //a bit hacky :)
        connect (m_mergeCatalog,SIGNAL(signalEntryModified(DocPosition)),this,SLOT(slotUpdate(DocPosition)));

        if (m_pos.entry!=-1)
            slotNewEntryDisplayed(m_pos);
        show();
    }
    else
    {
        //KMessageBox::error(this, KIO::NetAccess::lastErrorString() );
        cleanup();
        if (errorLine>0)
            KMessageBox::error(this, i18nc("@info","Error opening the file <filename>%1</filename> for synchronization, error line: %2",url.pathOrUrl(),errorLine) );
        else
        {
            /* disable this as requested by bug 272587
            KNotification* notification=new KNotification("MergeFilesOpenError", this);
            notification->setText( i18nc("@info %1 is full filename","Error opening the file <filename>%1</filename> for synchronization",url.pathOrUrl()) );
            notification->sendEvent();
            */
        }
        //i18nc("@info %1 is w/o path","No branch counterpart for <filename>%1</filename>",url.fileName()),
    }

}