Example #1
0
MessageItem* MessageItem::create(char *msg, int time/*time=2*/)
{
	MessageItem *mi = new MessageItem();
	mi->autorelease();
	mi->init(msg, time);

	return mi;
}
Example #2
0
void MessageModel::setTranslation(const iterator &it, const QString &translation)
{
    int c = it.contextNo();
    int m = it.messageNo();
    QModelIndex idx = modelIndex(c, m, 2);
    MessageItem *msg = it.current();
    msg->setTranslation(translation);
    emit dataChanged(idx, idx);
}
Example #3
0
void MessageOutput::clickItem( QListBoxItem * l_item )
{
   MessageItem *item = dynamic_cast<MessageItem*>(l_item);
   if ( item )  {
//     kdDebug(24000) << "Column: " << item->column() << endl;
     if ( item->line() != -1  )
       emit clicked( item->fileName(), item->line() - 1, item->column() - 1);
   }
}
Example #4
0
MessageItem *ContextItem::findMessage(const QString &sourcetext, const QString &comment) const
{
    for (int i = 0; i < messageCount(); ++i) {
        MessageItem *mi = messageItem(i);
        if (mi->text() == sourcetext && mi->comment() == comment)
            return mi;
    }
    return 0;
}
Example #5
0
void MessageOutput::addToLastItem(const QString& s)
{
  int ind = count() - 1;
  if ( ind != -1 ) {
    MessageItem *it = dynamic_cast<MessageItem*>( item(ind) );
    if ( it )
      it->addText( s );
    else
      changeItem( text( ind )+ s, ind );
  }
}
Example #6
0
static int calcMergeScore(const DataModel *one, const DataModel *two)
{
    int inBoth = 0;
    for (int i = 0; i < two->contextCount(); ++i) {
        ContextItem *oc = two->contextItem(i);
        if (ContextItem *c = one->findContext(oc->context())) {
            for (int j = 0; j < oc->messageCount(); ++j) {
                MessageItem *m = oc->messageItem(j);
                if (c->findMessage(m->text(), m->comment()))
                    ++inBoth;
            }
        }
    }
    return inBoth * 100 / two->messageCount();
}
Example #7
0
void MessageOutput::showMessage(int line, int col, const QString &fileName, const QString& s, bool append)
{
  MessageItem *it = 0L;
  QString message = s;
  int endPos;
  if ( !count() || (!append && !text(count()-1).stripWhiteSpace().isEmpty()) )
    it = insertItem("");
  while ( ( endPos = message.find('\n') ) != -1 ) {
    if (it)
    {
      it->setLine(line);
      it->setColumn(col);
      it->setFileName(fileName);
    }
    addToLastItem( message.left(endPos) );
    it = insertItem("");
    message.remove(0,endPos+1);
  }
  if (!message.isEmpty())
  {
    if (it)
    {
      it->setLine(line);
      it->setColumn(col);
      it->setFileName(fileName);
    }
    addToLastItem( message);
  }
  setBottomItem(count()>0?count()-1:0);
}
void Widget::setStorageModel( StorageModel * storageModel, PreSelectionMode preSelectionMode )
{
  if ( storageModel == d->mStorageModel )
    return; // nuthin to do here

  if ( d->mStorageModel )
  {
    // Save the current selection
    MessageItem * lastSelectedMessageItem = d->mView->currentMessageItem( false );
    Manager::instance()->savePreSelectedMessageForStorageModelId(
        d->mLastStorageModelId,
        lastSelectedMessageItem ? lastSelectedMessageItem->uniqueId() : 0
      );
  }

  d->setDefaultAggregationForStorageModel( storageModel );
  d->setDefaultThemeForStorageModel( storageModel );
  d->setDefaultSortOrderForStorageModel( storageModel );

  if ( d->mSearchTimer )
  {
    d->mSearchTimer->stop();
    delete d->mSearchTimer;
    d->mSearchTimer = 0;
  }

  d->mSearchEdit->setText( QString() );

  if ( d->mFilter ) {
    resetFilter();
  }

  StorageModel * oldModel = d->mStorageModel;

  d->mStorageModel = storageModel;
  d->mLastStorageModelId = storageModel ? storageModel->id() : 0;

  d->mView->setStorageModel( d->mStorageModel, preSelectionMode );

  delete oldModel;

  d->mStatusFilterCombo->setEnabled( d->mStorageModel );
  d->mSearchEdit->setEnabled( d->mStorageModel );
}
Example #9
0
MessageItem *MessageModel::findMessage(const char *context, const char *sourcetext, const char *comment /*= 0*/) const
{
    for (int c = 0; c < cntxtList.count(); ++c) {
        ContextItem *ctx = cntxtList.at(c);
        if (ctx->context() == QLatin1String(context)) {
            QList<MessageItem*> items = ctx->messageItemList();
            for (int i = 0; i < items.count(); ++i) {
                MessageItem *mi = items.at(i);
                if (mi->sourceText() == QLatin1String(sourcetext)) {
                    if (comment) {
                        if (mi->comment() != QLatin1String(comment)) continue;
                    }
                    return mi;
                }
            }
            break;
        }
    }
    return 0;
}
Example #10
0
bool MessageModel::findMessage(int *contextNo, int *itemNo, const QString &findText, int findWhere, 
    bool matchSubstring, Qt::CaseSensitivity cs)
{
    bool found = false;
    if (contextsInList() <= 0)
        return false;

    int pass = 0;
    int scopeNum = *contextNo;
    int itemNum = *itemNo;

    MessageItem *m = 0;

    // We want to search the scope we started from *again*, since we did not necessarily search that *completely* when we started.
    // (Problaby we started somewhere in the middle of it.)
    // Therefore, "pass <=" and not "pass < " 
    while (!found && pass <= contextsInList()) {
        ContextItem *c = contextList().at(scopeNum);
        for (int mit = itemNum; mit < c->messageItemsInList() ; ++mit) {
            m = c->messageItem(mit);
            QString searchText;
            switch (findWhere) {
                case SourceText:
                    searchText = m->sourceText();
                    break;
                case Translations:
                    searchText = m->translation();
                    break;
                case Comments:
                    searchText = m->comment();
                    break;
            }
            if (matchSubstring) {
                if (searchText.indexOf(findText,0, cs) >= 0) {
                    found = true;
                    break;
                }
            } else {
                if (cs == Qt::CaseInsensitive) {
                    if (findText.toLower() == searchText.toLower()) {
                        found = true;
                        break;
                    }
                } else {
                    if ( findText == searchText ) {
                        found = true;
                        break;
                    }
                }
            }

        }
        itemNum = 0;
        ++pass;

        ++scopeNum;
        if (scopeNum >= contextsInList()) {
            scopeNum = 0;
            //delayedMsg = tr("Search wrapped.");
        }
    }

    if (found) {
        *itemNo = itemNum;
        *contextNo = scopeNum;
    }
    return found;
}
Example #11
0
QString MessageModelTranslator::translate(const char *context, const char *sourcetext, const char *comment /*= 0*/) const
{
    MessageItem *m = messageModel()->findMessage(context, sourcetext, comment);
    return m ? m->translation() : QString();
}
Example #12
0
bool MessageModel::finished(const QModelIndex &index)
{
    MessageItem *m = messageItem(index);
    return m->finished();
}
Example #13
0
QVariant MessageModel::data(const QModelIndex &index, int role) const
{
    int row = index.row();
    int column = index.column();

    ContextItem *cntxtItem = static_cast<ContextItem *>(index.internalPointer());
    if (cntxtItem) {
        if (row >= cntxtItem->messageItemsInList() || !index.isValid())
            return QVariant();

        MessageItem *msgItem = cntxtItem->messageItem(row);

        if (role == Qt::DisplayRole) {
            switch(column) {
            case 0: // done
                return QVariant();
            case 1: // source text
			    return msgItem->sourceText().simplified();
            case 2: // translation
                return msgItem->translation().simplified();
            }
        }
        else if ((role == Qt::DecorationRole) && (column == 0)) {
            if (msgItem->message().type() == MetaTranslatorMessage::Unfinished && msgItem->translation().isEmpty())
                return qVariantFromValue(*TrWindow::pxEmpty);
            else if (msgItem->message().type() == MetaTranslatorMessage::Unfinished && msgItem->danger())
                return qVariantFromValue(*TrWindow::pxDanger);
            else if (msgItem->message().type() == MetaTranslatorMessage::Finished && msgItem->danger())
                return qVariantFromValue(*TrWindow::pxWarning);
            else if (msgItem->message().type() == MetaTranslatorMessage::Finished)
                return qVariantFromValue(*TrWindow::pxOn);
            else if (msgItem->message().type() == MetaTranslatorMessage::Unfinished)
                return qVariantFromValue(*TrWindow::pxOff);
            else if (msgItem->message().type() == MetaTranslatorMessage::Obsolete)
                return qVariantFromValue(*TrWindow::pxObsolete);
        }
    } else {
        if (row >= cntxtList.count() || !index.isValid())
            return QVariant();

        ContextItem *cntxtItem = cntxtList.at(row);

        if (role == Qt::DisplayRole) {
            switch(column) {
            case 0: // done
                return QVariant();
            case 1: // context
                return cntxtItem->context().simplified();
            case 2: // items
                QString s;
                int itemCount = cntxtItem->messageItemsInList();
                int obsoleteCount = cntxtItem->obsolete();
                int finishedCount = cntxtItem->finishedCount();
                s.sprintf("%d/%d", finishedCount,
                    itemCount - obsoleteCount);
                return s;
            }
        }
        else if ((role == Qt::DecorationRole) && (column == 0)) {
            if (cntxtItem->isContextObsolete())
                return qVariantFromValue(*TrWindow::pxObsolete);
            else if (cntxtItem->isFinished())
                return qVariantFromValue(*TrWindow::pxOn);
            else
                return qVariantFromValue(*TrWindow::pxOff);
        }
    }
    return QVariant();
}
Example #14
0
QStringList DataModel::normalizedTranslations(const MessageItem &m) const
{
    return Translator::normalizedTranslations(m.message(), m_numerusForms.count());
}
Example #15
0
bool MessageModel::load(const QString &fileName)
{
    MetaTranslator tor;
    bool ok = tor.load(fileName);
    if (ok) {
        if(tor.codecForTr())
            m_codecForTr = tor.codecForTr()->name();
        int messageCount = 0;
        clearContextList();
        m_numFinished = 0;
        m_numNonobsolete = 0;

        TML all = tor.messages();
        QHash<QString, ContextItem*> contexts;

        m_srcWords = 0;
        m_srcChars = 0;
        m_srcCharsSpc = 0;

        foreach(MetaTranslatorMessage mtm, all) {
            QCoreApplication::processEvents();
            ContextItem *c;
            if (contexts.contains(QLatin1String(mtm.context()))) {
                c = contexts.value( QLatin1String(mtm.context()));
            }
            else {
                c = createContextItem(tor.toUnicode(mtm.context(), mtm.utf8()));;
                appendContextItem(c);
                contexts.insert(QLatin1String(mtm.context()), c);
            }
            if (QByteArray(mtm.sourceText()) == ContextComment) {
                c->appendToComment(tor.toUnicode(mtm.comment(), mtm.utf8()));
            }
            else {
                MessageItem *tmp = new MessageItem(mtm, tor.toUnicode(mtm.sourceText(),
                    mtm.utf8()), tor.toUnicode(mtm.comment(), mtm.utf8()), c);
                if (mtm.type() != MetaTranslatorMessage::Obsolete) {
                    m_numNonobsolete++;
                    //if (mtm.type() == MetaTranslatorMessage::Finished)
                        //tmp->setFinished(true);
                        //++m_numFinished;
                    doCharCounting(tmp->sourceText(), m_srcWords, m_srcChars, m_srcCharsSpc);
                }
                else {
                    c->incrementObsoleteCount();
                }
                c->appendMessageItem(tmp);
                ++messageCount;
            }
        }

        // Try to detect the correct language in the following order
        // 1. Look for the language attribute in the ts 
        //   if that fails
        // 2. Guestimate the language from the filename (expecting the qt_{en,de}.ts convention)
        //   if that fails
        // 3. Retrieve the locale from the system.
        QString lang = tor.languageCode();
        if (lang.isEmpty()) {
            int pos_sep = fileName.indexOf(QLatin1Char('_'));
            if (pos_sep != -1 && pos_sep + 3 <= fileName.length()) {
                lang = fileName.mid(pos_sep + 1, 2);
            }
        }
        QLocale::Language l;
        QLocale::Country c;
        MetaTranslator::languageAndCountry(lang, &l, &c);
        if (l == QLocale::C) {
            QLocale sys;
            l = sys.language();
            c = sys.country();
        }
        setLanguage(l);
        setCountry(c);

        m_numMessages = messageCount;
        updateAll();
        setModified(false);
    }
Example #16
0
QStringList MessageModel::normalizedTranslations(const MessageItem &m) const
{
    return MetaTranslator::normalizedTranslations(m.message(), m_language, m_country);
}
Example #17
0
/*!
  Adds the error message.\n
  Moves to the most recent error message in the view.
  */
void MessagesWidget::addGUIMessage(MessageItem messageItem)
{
  // move the cursor down before adding message.
  QTextCursor textCursor = mpMessagesTextBrowser->textCursor();
  textCursor.movePosition(QTextCursor::End);
  mpMessagesTextBrowser->setTextCursor(textCursor);
  // set the CSS class depending on message type
  QString messageCSSClass;
  switch (messageItem.getErrorType()) {
    case StringHandler::Warning:
      messageCSSClass = "warning";
      break;
    case StringHandler::OMError:
      messageCSSClass = "error";
      break;
    case StringHandler::Notification:
    default:
      messageCSSClass = "notification";
      break;
  }
  QString linkFormat = QString("[%1: %2]: <a href=\"omeditmessagesbrowser:///%3?lineNumber=%4\">%5</a>");
  QString errorMessage;
  QString message;
  if(messageItem.getMessageItemType()== MessageItem::Modelica) {
    // if message already have tags then just use it.
    if (Qt::mightBeRichText(messageItem.getMessage())) {
      message = messageItem.getMessage();
    } else {
      message = Qt::convertFromPlainText(messageItem.getMessage()).remove("<p>").remove("</p>");
    }
  } else if(messageItem.getMessageItemType()== MessageItem::TLM) {
    message = messageItem.getMessage().remove("<p>");
  }
  if (messageItem.getFileName().isEmpty()) { // if custom error message
    errorMessage = message;
  } else if (messageItem.getMessageItemType()== MessageItem::TLM ||
             mpMainWindow->getLibraryWidget()->getLibraryTreeModel()->findLibraryTreeItem(messageItem.getFileName())) {
    // If the class is only loaded in AST via loadString then create link for the error message.
    errorMessage = linkFormat.arg(messageItem.getFileName())
        .arg(messageItem.getLocation())
        .arg(messageItem.getFileName())
        .arg(messageItem.getLineStart())
        .arg(message);
  } else {
    // Find the class name using the file name and line number.
    LibraryTreeItem *pLibraryTreeItem;
    pLibraryTreeItem = mpMainWindow->getLibraryWidget()->getLibraryTreeModel()->getLibraryTreeItemFromFile(messageItem.getFileName(),
                                                                                                           messageItem.getLineStart().toInt());
    if (pLibraryTreeItem) {
      errorMessage = linkFormat.arg(pLibraryTreeItem->getNameStructure())
          .arg(messageItem.getLocation())
          .arg(pLibraryTreeItem->getNameStructure())
          .arg(messageItem.getLineStart())
          .arg(message);
    } else {
      // otherwise display filename to user where error occurred.
      errorMessage = QString("[%1: %2]: %3")
          .arg(messageItem.getFileName())
          .arg(messageItem.getLocation())
          .arg(message);
    }
  }
  QString errorString = QString("<div class=\"%1\">"
                                "<b>[%2] %3 %4 %5</b><br>"
                                "%6"
                                "</div><br>")
      .arg(messageCSSClass)
      .arg(QString::number(mMessageNumber))
      .arg(QTime::currentTime().toString())
      .arg(StringHandler::getErrorKindString(messageItem.getErrorKind()))
      .arg(StringHandler::getErrorTypeDisplayString(messageItem.getErrorType()))
      .arg(errorMessage);
  mpMessagesTextBrowser->insertHtml(errorString);
  mMessageNumber++;
  // move the cursor down after adding message.
  textCursor.movePosition(QTextCursor::End);
  mpMessagesTextBrowser->setTextCursor(textCursor);
  emit MessageAdded();
}
Example #18
0
void MessagesLayer::doing(float dt)
{
	if (!_messages) return;

	int count = _messages->count();


	if (_curShowItem)
	{
		_curShowItem->update(dt);
	}

	if (_curShowItem==nullptr || _curShowItem->timeOver())
	{
		LayerRGBA* _node = nullptr;
		if (_curShowItem)
		{
			_node = _curShowItem->getNode();
			_node->stopAllActions();
			auto action = Sequence::create(
				MoveBy::create(0.3f, Point(0, 100)),
				CallFuncN::create(
					std::bind([&](Node *node){ node->removeFromParent();}, std::placeholders::_1)
					),
				NULL
				);
			_node->runAction(action);
			auto action2 = FadeOut::create(0.3f);
			_node->runAction(action2);
			_node = nullptr;
			CC_SAFE_RELEASE_NULL(_curShowItem);
		}

		if (count > 0)
		{
			Object *obj = _messages->getLastObject();
			if (obj)
			{
				MessageItem *item = static_cast<MessageItem*>(obj);
				if (item)
				{
				
					_node = item->getNode();
					_node->setOpacity(0);
					_node->setPosition(Point(_contentSize.width/2, _contentSize.height/2-40));
					addChild(_node);

					auto action = MoveBy::create(0.2f, Point(0, 40));
					_node->runAction(action);
					auto action2 = FadeIn::create(0.2f);
					_node->runAction(action2);
					_node = nullptr;

					_curShowItem = item;
					_curShowItem->retain();
					_messages->removeObject(obj);
				}
			}
		}
	}

}