Commit b1e37cc7 authored by Simon Depiets's avatar Simon Depiets
Browse files

Adding a comment feature on Project files

parent a419a605
......@@ -237,6 +237,17 @@ QString Project::absolutePath(const QString& possiblyRelPath) const
return possiblyRelPath;
}
QString Project::relativePath(const QString& possiblyAbsPath) const
{
if (QFileInfo(possiblyAbsPath).isAbsolute()) {
if (projectDir().endsWith('/'))
return QString(possiblyAbsPath).remove(projectDir());
return QString(possiblyAbsPath).remove(projectDir() + QLatin1Char('/'));
}
return possiblyAbsPath;
}
void Project::populateDirModel()
{
if (Q_UNLIKELY(m_path.isEmpty() || !QFileInfo::exists(poDir())))
......
......@@ -149,6 +149,7 @@ public slots:
}
Q_SCRIPTABLE QString absolutePath(const QString&) const;
Q_SCRIPTABLE QString relativePath(const QString&) const;
Q_SCRIPTABLE void setDesirablePath(const QString& path)
{
......
......@@ -92,4 +92,12 @@
<default>80</default>
</entry>
</group>
<group name="Comments">
<entry name="CommentsFiles" type="StringList">
<default></default>
</entry>
<entry name="CommentsTexts" type="StringList">
<default></default>
</entry>
</group>
</kcfg>
......@@ -537,6 +537,8 @@ QVariant ProjectModel::headerData(int section, Qt::Orientation, int role) const
return i18nc("@title:column Number of fuzzy or untranslated entries", "Incomplete");
case ProjectModelColumns::TranslationDate:
return i18nc("@title:column", "Last Translation");
case ProjectModelColumns::Comment:
return i18nc("@title:column", "Comment");
case ProjectModelColumns::SourceDate:
return i18nc("@title:column", "Template Revision");
case ProjectModelColumns::LastTranslator:
......@@ -640,6 +642,11 @@ QVariant ProjectModel::data(const QModelIndex& index, const int role) const
const int translated = node->translatedAsPerRole();
const int fuzzy = node->fuzzyAsPerRole();
const int untranslated = node->metaData.untranslated;
QString comment(QStringLiteral(""));
int existingItem = Project::instance()->commentsFiles().indexOf(Project::instance()->relativePath(item.localPath()));
if (existingItem != -1 && Project::instance()->commentsTexts().count() > existingItem) {
comment = Project::instance()->commentsTexts().at(existingItem);
}
switch (role) {
case Qt::TextAlignmentRole:
......@@ -660,6 +667,8 @@ QVariant ProjectModel::data(const QModelIndex& index, const int role) const
return hasStats ? untranslated : QVariant();
case ProjectModelColumns::IncompleteCount:
return hasStats ? (untranslated + fuzzy) : QVariant();
case ProjectModelColumns::Comment:
return comment;
case ProjectModelColumns::SourceDate:
return node->metaData.sourceDate;
case ProjectModelColumns::TranslationDate:
......
......@@ -128,6 +128,7 @@ public:
FuzzyCount,
UntranslatedCount,
IncompleteCount,
Comment,
SourceDate,
TranslationDate,
LastTranslator,
......
......@@ -53,6 +53,7 @@
#include <QStackedLayout>
#include <QLabel>
#include <QPushButton>
#include <QInputDialog>
ProjectTab::ProjectTab(QWidget *parent)
: LokalizeSubwindowBase2(parent)
......@@ -268,6 +269,7 @@ void ProjectTab::contextMenuEvent(QContextMenuEvent *event)
menu->addAction(i18nc("@action:inmenu", "Add to translation memory"), this, &ProjectTab::scanFilesToTM);
menu->addAction(i18nc("@action:inmenu", "Search in files"), this, &ProjectTab::searchInFiles);
menu->addAction(i18nc("@action:inmenu", "Add a comment"), this, &ProjectTab::addComment);
if (Settings::self()->pologyEnabled()) {
menu->addAction(i18nc("@action:inmenu", "Launch Pology on files"), this, &ProjectTab::pologyOnFiles);
}
......@@ -281,7 +283,6 @@ void ProjectTab::contextMenuEvent(QContextMenuEvent *event)
// menu.addAction(i18n("Force Scanning"),this,&ProjectTab::slotForceStats);
//
// }
menu->popup(event->globalPos());
}
......@@ -291,6 +292,41 @@ void ProjectTab::scanFilesToTM()
TM::scanRecursive(m_browser->selectedItems(), Project::instance()->projectID());
}
void ProjectTab::addComment()
{
QStringList files = m_browser->selectedItems();
int i = files.size();
QStringList previousCommentsTexts = Project::instance()->commentsTexts();
QStringList previousCommentsFiles = Project::instance()->commentsFiles();
QString previousComment(QStringLiteral(""));
if (i >= 1) {
//Retrieve previous comment (first one)
int existingItem = previousCommentsFiles.indexOf(Project::instance()->relativePath(files.at(0)));
if (existingItem != -1 && previousCommentsTexts.count() > existingItem) {
previousComment = previousCommentsTexts.at(existingItem);
}
}
bool ok;
QString newComment = QInputDialog::getText(this, i18n("Project file comment"), i18n("Input a comment for this project file:"), QLineEdit::Normal, previousComment, &ok);
if (!ok)
return;
while (--i >= 0) {
QString filePath = Project::instance()->relativePath(files.at(i));
int existingItem = previousCommentsFiles.indexOf(filePath);
if (existingItem != -1 && previousCommentsTexts.count() > existingItem) {
previousCommentsTexts[existingItem] = newComment;
} else {
previousCommentsTexts << newComment;
previousCommentsFiles << filePath;
}
}
Project::instance()->setCommentsTexts(previousCommentsTexts);
Project::instance()->setCommentsFiles(previousCommentsFiles);
Project::instance()->save();
}
void ProjectTab::searchInFiles(bool templ)
{
QStringList files = m_browser->selectedItems();
......
......@@ -93,6 +93,7 @@ private slots:
void setFocus();
void scanFilesToTM();
void pologyOnFiles();
void addComment();
void searchInFiles(bool templ = false);
void searchInFilesInclTempl();
void openFile();
......
......@@ -271,6 +271,7 @@ bool SortFilterProxyModel::lessThan(const QModelIndex& left,
case ProjectModel::ProjectModelColumns::LastTranslator:
case ProjectModel::ProjectModelColumns::SourceDate:
case ProjectModel::ProjectModelColumns::TranslationDate:
case ProjectModel::ProjectModelColumns::Comment:
return collator.compare(projectModel->data(left).toString(), projectModel->data(right).toString()) < 0;
case ProjectModel::ProjectModelColumns::TotalCount:
case ProjectModel::ProjectModelColumns::TranslatedCount:
......@@ -301,8 +302,8 @@ ProjectWidget::ProjectWidget(/*Catalog* catalog, */QWidget* parent)
setUniformRowHeights(true);
setAllColumnsShowFocus(true);
int widthDefaults[] = {6, 1, 1, 1, 1, 1, 1, 4, 4, 4};
//FileName, Graph, TotalCount, TranslatedCount, FuzzyCount, UntranslatedCount, IncompleteCount, SourceDate, TranslationDate, LastTranslator
int widthDefaults[] = {6, 1, 1, 1, 1, 1, 1, 4, 4, 4, 4};
//FileName, Graph, TotalCount, TranslatedCount, FuzzyCount, UntranslatedCount, IncompleteCount, Comment, SourceDate, TranslationDate, LastTranslator
int i = sizeof(widthDefaults) / sizeof(int);
int baseWidth = columnWidth(0);
while (--i >= 0)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment