コード例 #1
0
ファイル: QtHighlightEditor.cpp プロジェクト: jyhong836/swift
std::string formatShortDescription(const HighlightRule &rule)
{
	const std::string chatOrRoom = (rule.getMatchChat() ? "chat" : "room");

	std::vector<std::string> senders = rule.getSenders();
	std::vector<std::string> keywords = rule.getKeywords();

	if (senders.empty() && keywords.empty() && !rule.getNickIsKeyword()) {
		return std::string("All ") + chatOrRoom + " messages.";
	}

	if (rule.getNickIsKeyword()) {
		return std::string("All ") + chatOrRoom + " messages that mention my name.";
	}

	if (!senders.empty()) {
		return std::string("All ") + chatOrRoom + " messages from " + senders[0] + ".";
	}

	if (!keywords.empty()) {
		return std::string("All ") + chatOrRoom + " messages mentioning the keyword '" + keywords[0] + "'.";
	}

	return "Unknown Rule";
}
コード例 #2
0
ファイル: QtHighlightEditor.cpp プロジェクト: jyhong836/swift
void QtHighlightEditor::onNewButtonClicked()
{
	int row = getSelectedRow() + 1;
	populateList();
	HighlightRule newRule;
	newRule.setMatchMUC(true);
	highlightManager_->insertRule(row, newRule);
	QListWidgetItem *item = new QListWidgetItem();
	item->setText(P2QSTRING(formatShortDescription(newRule)));
	QFont font;
	font.setItalic(true);
	item->setFont(font);
	ui_.listWidget->insertItem(row, item);
	selectRow(row);
}
コード例 #3
0
std::vector<HighlightRule> HighlightManager::getDefaultRules()
{
	std::vector<HighlightRule> rules;

	HighlightRule chatNotificationRule;
	chatNotificationRule.setMatchChat(true);
	chatNotificationRule.getAction().setPlaySound(true);
	chatNotificationRule.setMatchWholeWords(true);
	rules.push_back(chatNotificationRule);

	HighlightRule selfMentionMUCRule;
	selfMentionMUCRule.setMatchMUC(true);
	selfMentionMUCRule.getAction().setPlaySound(true);
	selfMentionMUCRule.setNickIsKeyword(true);
	selfMentionMUCRule.setMatchCase(true);
	selfMentionMUCRule.setMatchWholeWords(true);
	rules.push_back(selfMentionMUCRule);

	return rules;
}
コード例 #4
0
bool HighlightState::findBestMatch(std::string::const_iterator start,
                                   std::string::const_iterator end, HighlightToken &token,
                                   const MatchingParameters &params) const {
    HighlightToken bestToken, tempToken;
    const HighlightRule *bestMatchingRule = 0;
    HighlightRule *currentRule = 0;
    bool first = true;

    for (RuleList::const_iterator it = ruleList.begin(); it != ruleList.end(); ++it) {
        currentRule = (*it).get();
        tempToken.clearMatched();

        if (currentRule->tryToMatch(start, end, tempToken, params)) {
            if (first || betterThan(tempToken, bestToken)) {
                // the first one, it's always the best
                if (first) {
                    first = false;
                }
                bestToken.copyFrom(tempToken);
                bestMatchingRule = currentRule;

                // if we matched something with no prefix (or only spaces)...
                if (tempToken.prefixOnlySpaces) {
                    // ...don't try any other rule
                    break;
                }
            }
        }
    }

    if (!first) {
        // we found the best matching rule
        token.copyFrom(bestToken);
        token.rule = bestMatchingRule;
        return true;
    }

    return false;
}
コード例 #5
0
	static HighlightRule ruleFromKeyword(const std::string& keyword, bool matchCase, bool matchWholeWord)
	{
		HighlightRule rule;
		std::vector<std::string> keywords;
		keywords.push_back(keyword);
		rule.setKeywords(keywords);
		rule.setMatchCase(matchCase);
		rule.setMatchWholeWords(matchWholeWord);
		rule.setMatchChat(true);
		rule.getAction().setTextBackground("white");
		return rule;
	}
コード例 #6
0
	static HighlightRulesListPtr ruleListWithNickHighlight(bool withHighlightColour = true)
	{
		HighlightRule rule;
		rule.setMatchChat(true);
		rule.setNickIsKeyword(true);
		rule.setMatchCase(true);
		rule.setMatchWholeWords(true);
		if (withHighlightColour) {
			rule.getAction().setTextBackground("white");
		}
		boost::shared_ptr<HighlightManager::HighlightRulesList> list = boost::make_shared<HighlightManager::HighlightRulesList>();
		list->addRule(rule);
		return list;
	}
コード例 #7
0
ファイル: QtHighlightEditor.cpp プロジェクト: jyhong836/swift
void QtHighlightEditor::ruleToDialog(const HighlightRule& rule)
{
	ui_.chatRadio->setEnabled(true);
	ui_.roomRadio->setEnabled(true);

	if (rule.getMatchMUC()) {
		ui_.chatRadio->setChecked(false);
		ui_.roomRadio->setChecked(true);
	} else {
		ui_.chatRadio->setChecked(true);
		ui_.roomRadio->setChecked(false);
	}

	ui_.allMsgRadio->setEnabled(true);
	ui_.allMsgRadio->setChecked(true); /* this is the default radio button */
	jid_->setText("");
	ui_.keyword->setText("");
	ui_.matchPartialWords->setChecked(false);
	ui_.matchCase->setChecked(false);

	ui_.nickIsKeyword->setEnabled(true);
	if (rule.getNickIsKeyword()) {
		ui_.nickIsKeyword->setChecked(true);
	}

	ui_.senderRadio->setEnabled(true);
	std::vector<std::string> senders = rule.getSenders();
	if (!senders.empty()) {
		ui_.senderRadio->setChecked(true);
		jid_->setText(P2QSTRING(senders[0]));
	}

	ui_.keywordRadio->setEnabled(true);
	std::vector<std::string> keywords = rule.getKeywords();
	if (!keywords.empty()) {
		ui_.keywordRadio->setChecked(true);
		ui_.keyword->setText(P2QSTRING(keywords[0]));
		ui_.matchPartialWords->setChecked(!rule.getMatchWholeWords());
		ui_.matchCase->setChecked(rule.getMatchCase());
	}

	const HighlightAction& action = rule.getAction();

	ui_.noColorRadio->setEnabled(true);
	ui_.customColorRadio->setEnabled(true);
	if (action.getTextColor().empty() && action.getTextBackground().empty()) {
		ui_.noColorRadio->setChecked(true);
		ui_.foregroundColor->setEnabled(false);
		ui_.backgroundColor->setEnabled(false);
	} else {
		ui_.foregroundColor->setEnabled(true);
		ui_.backgroundColor->setEnabled(true);
		QColor foregroundColor(P2QSTRING(action.getTextColor()));
		ui_.foregroundColor->setColor(foregroundColor);
		QColor backgroundColor(P2QSTRING(action.getTextBackground()));
		ui_.backgroundColor->setColor(backgroundColor);
		ui_.customColorRadio->setChecked(true);
	}

	ui_.noSoundRadio->setEnabled(true);
	ui_.defaultSoundRadio->setEnabled(true);
	ui_.customSoundRadio->setEnabled(true);
	ui_.soundFile->setText("");
	ui_.soundFile->setEnabled(false);
	ui_.soundFileButton->setEnabled(false);
	if (action.playSound()) {
		if (action.getSoundFile().empty()) {
			ui_.defaultSoundRadio->setChecked(true);
		} else {
			ui_.customSoundRadio->setChecked(true);
			ui_.soundFile->setText(P2QSTRING(action.getSoundFile()));
			ui_.soundFile->setEnabled(true);
			ui_.soundFileButton->setEnabled(true);
		}
	} else {
		ui_.noSoundRadio->setChecked(true);
	}

	/* set radio button child option states */
	setChildWidgetStates();
}
コード例 #8
0
ファイル: QtHighlightEditor.cpp プロジェクト: jyhong836/swift
HighlightRule QtHighlightEditor::ruleFromDialog()
{
	HighlightRule rule;
	HighlightAction& action = rule.getAction();

	if (ui_.chatRadio->isChecked()) {
		rule.setMatchChat(true);
		rule.setMatchMUC(false);
	} else {
		rule.setMatchChat(false);
		rule.setMatchMUC(true);
	}

	if (ui_.senderRadio->isChecked()) {
		QString senderName = jid_->text();
		if (!senderName.isEmpty()) {
			std::vector<std::string> senders;
			senders.push_back(Q2PSTRING(senderName));
			rule.setSenders(senders);
			action.setHighlightAllText(true);
		}
	}

	if (ui_.keywordRadio->isChecked()) {
		QString keywordString = ui_.keyword->text();
		if (!keywordString.isEmpty()) {
			std::vector<std::string> keywords;
			keywords.push_back(Q2PSTRING(keywordString));
			rule.setKeywords(keywords);
		}
	}

	if (ui_.nickIsKeyword->isChecked()) {
		rule.setNickIsKeyword(true);
		rule.setMatchWholeWords(true);
		rule.setMatchCase(true);
	} else {
		rule.setMatchWholeWords(!ui_.matchPartialWords->isChecked());
		rule.setMatchCase(ui_.matchCase->isChecked());
	}

	if (ui_.noColorRadio->isChecked()) {
		action.setTextColor("");
		action.setTextBackground("");
	} else {
		action.setTextColor(Q2PSTRING(ui_.foregroundColor->getColor().name()));
		action.setTextBackground(Q2PSTRING(ui_.backgroundColor->getColor().name()));
	}

	if (ui_.noSoundRadio->isChecked()) {
		action.setPlaySound(false);
	} else if (ui_.defaultSoundRadio->isChecked()) {
		action.setPlaySound(true);
		action.setSoundFile("");
	} else {
		action.setPlaySound(true);
		action.setSoundFile(Q2PSTRING(ui_.soundFile->text()));
	}

	return rule;
}