/***************************************************************************
- * Copyright (C) 2005-08 by the Quassel Project *
+ * Copyright (C) 2005-09 by the Quassel Project *
* devel@quassel-irc.org *
* *
* This program is free software; you can redistribute it and/or modify *
AliasesModel::AliasesModel(QObject *parent)
: QAbstractItemModel(parent),
- _configChanged(false)
+ _configChanged(false),
+ _modelReady(false)
{
// we need this signal for future connects to reset the data;
connect(Client::instance(), SIGNAL(connected()), this, SLOT(clientConnected()));
connect(Client::instance(), SIGNAL(disconnected()), this, SLOT(clientDisconnected()));
+
if(Client::isConnected())
clientConnected();
else
}
QVariant AliasesModel::data(const QModelIndex &index, int role) const {
+ if(!_modelReady)
+ return QVariant();
+
if(!index.isValid() || index.row() >= rowCount() || index.column() >= columnCount())
return QVariant();
case Qt::ToolTipRole:
switch(index.column()) {
case 0:
- return "<b>The shortcut for the alias</b><br />"
+ return tr("<b>The shortcut for the alias</b><br />"
"It can be used as a regular slash command.<br /><br />"
- "<b>Example:</b> \"foo\" can be used per /foo";
+ "<b>Example:</b> \"foo\" can be used per /foo");
case 1:
- return "<b>The string the shortcut will be expanded to</b><br />"
+ return tr("<b>The string the shortcut will be expanded to</b><br />"
"<b>special variables:</b><br />"
- " - <b>$i</b> represenents the i'th parameter.<br />"
- " - <b>$i..j</b> represenents the i'th to j'th parameter separated by spaces.<br />"
- " - <b>$i..</b> represenents all parameters from i on separated by spaces.<br />"
+ " - <b>$i</b> represents the i'th parameter.<br />"
+ " - <b>$i..j</b> represents the i'th to j'th parameter separated by spaces.<br />"
+ " - <b>$i..</b> represents all parameters from i on separated by spaces.<br />"
" - <b>$i:hostname</b> represents the hostname of the user identified by the i'th parameter or a * if unknown.<br />"
" - <b>$0</b> the whole string.<br />"
- " - <b>$currentnick</b> your current nickname<br />"
- " - <b>$channelname</b> the name of the selected channel<br /><br />"
+ " - <b>$nick</b> your current nickname<br />"
+ " - <b>$channel</b> the name of the selected channel<br /><br />"
"Multiple commands can be separated with semicolons<br /><br />"
- "<b>Example:</b> \"Test $1; Test $2; Test All $0\" will be expanded to three separate messages \"Test 1\", \"Test 2\" and \"Test All 1 2 3\" when called like /test 1 2 3";
+ "<b>Example:</b> \"Test $1; Test $2; Test All $0\" will be expanded to three separate messages \"Test 1\", \"Test 2\" and \"Test All 1 2 3\" when called like /test 1 2 3");
default:
return QVariant();
}
}
bool AliasesModel::setData(const QModelIndex &index, const QVariant &value, int role) {
+ if(!_modelReady)
+ return false;
+
if(!index.isValid() || index.row() >= rowCount() || index.column() >= columnCount() || role != Qt::EditRole)
return false;
QString newValue = value.toString();
if(newValue.isEmpty())
return false;
-
+
switch(index.column()) {
case 0:
if(aliasManager().contains(newValue)) {
}
void AliasesModel::loadDefaults() {
+ if(!_modelReady)
+ return;
+
AliasManager &manager = cloneAliasManager();
if(!manager.isEmpty()) {
QVariant AliasesModel::headerData(int section, Qt::Orientation orientation, int role) const {
QStringList header;
header << tr("Alias")
- << tr("Expansion");
-
+ << tr("Expansion");
+
if(orientation == Qt::Horizontal && role == Qt::DisplayRole)
return header[section];
if(_configChanged)
return _clonedAliasManager;
else
- return _aliasManager;
+ return *Client::aliasManager();
}
AliasManager &AliasesModel::aliasManager() {
if(_configChanged)
return _clonedAliasManager;
else
- return _aliasManager;
+ return *Client::aliasManager();
}
AliasManager &AliasesModel::cloneAliasManager() {
if(!_configChanged) {
- _clonedAliasManager = _aliasManager;
+ _clonedAliasManager = *Client::aliasManager();
_configChanged = true;
emit configChanged(true);
}
void AliasesModel::revert() {
if(!_configChanged)
return;
-
+
_configChanged = false;
emit configChanged(false);
reset();
if(!_configChanged)
return;
- _aliasManager.requestUpdate(_clonedAliasManager.toVariantMap());
+ Client::aliasManager()->requestUpdate(_clonedAliasManager.toVariantMap());
revert();
-}
+}
void AliasesModel::initDone() {
+ _modelReady = true;
reset();
emit modelReady(true);
}
void AliasesModel::clientConnected() {
- _aliasManager = AliasManager();
- Client::signalProxy()->synchronize(&_aliasManager);
- connect(&_aliasManager, SIGNAL(initDone()), this, SLOT(initDone()));
- connect(&_aliasManager, SIGNAL(updated(const QVariantMap &)), this, SLOT(revert()));
+ connect(Client::aliasManager(), SIGNAL(updated()), SLOT(revert()));
+ if(Client::aliasManager()->isInitialized())
+ initDone();
+ else
+ connect(Client::aliasManager(), SIGNAL(initDone()), SLOT(initDone()));
}
void AliasesModel::clientDisconnected() {
- // clear alias managers
- _aliasManager = AliasManager();
- _clonedAliasManager = AliasManager();
+ // clear
+ _clonedAliasManager = ClientAliasManager();
+ _modelReady = false;
reset();
emit modelReady(false);
}