Skip to content

Commit

Permalink
Fixed Issue 124
Browse files Browse the repository at this point in the history
Though history support is quite basic now.
Removed setConfugiration(QUrl) methods and accompanied stuff - deprecated by ServerProfilesModel.

git-svn-id: http://qtlobby.googlecode.com/svn/trunk@548 5a83989a-60d1-11de-a6a3-193033c112f2
  • Loading branch information
[email protected] committed Sep 9, 2009
1 parent 7d9c6ff commit 0968d14
Show file tree
Hide file tree
Showing 30 changed files with 433 additions and 138 deletions.
4 changes: 2 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,10 @@ set(QT_USE_QTXML true)
if(WIN32 OR BUILDBOT)
option(PURE_WINAPI_UNITSYNC_LOADER "Use pure Win API unitsync loader(helps against some loading bugs)" ON)
mark_as_advanced(PURE_WINAPI_UNITSYNC_LOADER)
find_package(Qt4 COMPONENTS QtCore QtGui QtScript QtNetwork QtOpenGL QtXml REQUIRED) # -QtDbus
find_package(Qt4 COMPONENTS QtCore QtGui QtScript QtNetwork QtOpenGL QtXml QtSql REQUIRED) # -QtDbus
else(WIN32 OR BUILDBOT)
set(QT_USE_QTDBUS true)
find_package(Qt4 COMPONENTS QtCore QtGui QtDbus QtScript QtNetwork QtOpenGL QtXml REQUIRED)
find_package(Qt4 COMPONENTS QtCore QtGui QtDbus QtScript QtNetwork QtOpenGL QtXml QtSql REQUIRED)
endif(WIN32 OR BUILDBOT)

find_package(QScintilla REQUIRED)
Expand Down
2 changes: 1 addition & 1 deletion buildbot/src/build.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ def run(self):
self.runCommand("rm -rf *")
self.runCommand("touch ../src/config.h")
self.runCommand("rm -f cbuild/src/qtlobby.*")
self.runCommand("cmake -DCMAKE_TOOLCHAIN_FILE=../toolchain-mingw.cmake -DBUILDBOT=ON -DTRANSLATIONS=OFF -DCMAKE_BUILD_TYPE=RelWithDebInfo ..")
self.runCommand("cmake -DCMAKE_TOOLCHAIN_FILE=../toolchain-mingw.cmake -DBUILDBOT=ON -DCMAKE_BUILD_TYPE=RelWithDebInfo ..")
self.runCommand("make")
os.chdir("src")
self.runCommand("objcopy --only-keep-debug qtlobby.exe qtlobby.dbg")
Expand Down
72 changes: 45 additions & 27 deletions src/AbstractChannel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@
// QtLobby released under the GPLv3, see COPYING for details.
#include "AbstractChannel.h"
#include "PathManager.h"

QString AbstractChannel::currentUsername;
#include "ServerProfilesModel.h"

AbstractChannel::AbstractChannel( QString name, QObject * parent ) : AbstractLobbyTab( parent ) {
setObjectName( name );
activeIcon = QIcon( P("icons/channel.xpm") );
inactiveIcon = QIcon( P("icons/channel_unread.xpm") );
activeTextColor = QColor("black");
inactiveTextColor = QColor("green");
historyMode = false;
}

AbstractChannel::~AbstractChannel() {}
Expand All @@ -19,12 +19,7 @@ void AbstractChannel::setupUi( QWidget * channelTabWidget ) {
channelTabWidget->setObjectName( QString::fromUtf8( "channelTabWidget" ) + objectName() );
channelTextBrowser = new ChannelTextBrowser( channelTabWidget );
channelTextBrowser->setObjectName( "channelTextBrowser" + objectName() );
channelTextBrowser->setOpenLinks(false);
channelTextBrowser->setReadOnly( true );
QTextDocument * channelTextDocument = new QTextDocument( channelTextBrowser );
//after exeeding the 500 blocks the first block will be removed
channelTextDocument->setMaximumBlockCount( 500 );
channelTextBrowser->setDocument( channelTextDocument );
setChannelBrowser(channelTextBrowser);
gridLayout = new QGridLayout( channelTabWidget );
gridLayout->setContentsMargins(0,0,0,0);
gridLayout->setObjectName( QString::fromUtf8( "channelGridLayout" ) + objectName() );
Expand Down Expand Up @@ -73,17 +68,17 @@ bool AbstractChannel::executeChannelInput( QString input ) {
ret.name = "CLIENTMSG";
QString row( "<tr><td style=\"padding:0;border:none;\">%1</td><td style=\"padding:0;border:none;\">%2</td></tr>" );
ret.attributes << objectName() << tr("Chat Help").append(" <table border=\"0\" cellpadding=\"0\" cellspacing=\"0\">%1</table>" ).arg(
row.arg( "/help, /h", tr( "Display this help" ) ) +
row.arg( "/channels, /list", tr( "Display channel list" ) ) +
row.arg( "/join, /j &lt;channel&gt;", tr( "Join channel" ) ) +
row.arg( "/j &lt;channel&gt; &lt;password&gt;", tr( "Join password protected channel" ) ) +
row.arg( "/j &lt;channel1&gt; &lt;password1&gt;, &lt;channel2&gt; ... ", tr( "Join multiple channels" ) ) +
row.arg( "/me &lt;text&gt;", tr( "Say highlighted" ) ) +
row.arg( "/sayver", tr( "Say /me is using QtLobby vXXX revYYY" ) ) +
row.arg( "/slap &lt;user&gt;", tr( "Say the mIRC slap sentence" ) ) +
row.arg( "/query, /msg &lt;user&gt;", tr( "Open private chat" ) ) +
row.arg( "/leave, /wc", tr( "Leave the channel" ) )
);
row.arg( "/help, /h", tr( "Display this help" ) ) +
row.arg( "/channels, /list", tr( "Display channel list" ) ) +
row.arg( "/join, /j &lt;channel&gt;", tr( "Join channel" ) ) +
row.arg( "/j &lt;channel&gt; &lt;password&gt;", tr( "Join password protected channel" ) ) +
row.arg( "/j &lt;channel1&gt; &lt;password1&gt;, &lt;channel2&gt; ... ", tr( "Join multiple channels" ) ) +
row.arg( "/me &lt;text&gt;", tr( "Say highlighted" ) ) +
row.arg( "/sayver", tr( "Say /me is using QtLobby vXXX revYYY" ) ) +
row.arg( "/slap &lt;user&gt;", tr( "Say the mIRC slap sentence" ) ) +
row.arg( "/query, /msg &lt;user&gt;", tr( "Open private chat" ) ) +
row.arg( "/leave, /wc", tr( "Leave the channel" ) )
);
receiveCommand( ret );
return true;
} else if ( QString( "/ingame" ).split( "," ).contains( firstWord, Qt::CaseInsensitive ) ) {
Expand All @@ -96,7 +91,12 @@ bool AbstractChannel::executeChannelInput( QString input ) {
}

void AbstractChannel::insertLine( QString line ) {
QString timeString = QString( "<span style=\"color:gray;\">%1</span> " ).arg( QTime().currentTime().toString( "[hh:mm:ss]" ) );
QTime t;
if(historyMode)
t = historyDateTime.time();
else
t = QTime::currentTime();
QString timeString = QString( "<span style=\"color:gray;\">%1</span> " ).arg( t.toString( "[hh:mm:ss]" ) );
bool scrollToMaximum = channelTextBrowser->verticalScrollBar()->value() == channelTextBrowser->verticalScrollBar()->maximum();
QTextCursor c = channelTextBrowser->textCursor();
//go to end of document
Expand All @@ -116,13 +116,13 @@ void AbstractChannel::insertLine( QString line ) {
QString AbstractChannel::makeHtml( QString in ) {
QString ret = in;
ret.replace( "\n", "<br>" );
if(historyMode) {
ret.prepend("<font color=\"gray\">");
ret.append("</font>");
}
return ret.prepend( "<p>" ).append( "</p>" );
}

void AbstractChannel::setCurrentUsername(QString user) {
currentUsername = user;
}

/*
2 \b Ctrl+B Bold (toggle)
15 \o Ctrl+O Normal (turn off bold, italic, underline, fixed pitch, reverse, and colors)
Expand Down Expand Up @@ -309,15 +309,16 @@ QString AbstractChannel::highlightUserName( QString input ) {
if( !Settings::Instance()->value("Chat/highlightUserName").toBool() )
return input;
// highlight currentUsername
QString pattern = currentUsername;
QString username = ServerProfilesModel::getInstance()->getActiveProfile().userName();
QString pattern = username;
pattern.replace("[", "\\[").replace("]", "\\]");
pattern += "(?!&gt;)";
input.replace(QRegExp(pattern), "<font style=\" font-weight:600; color:#aa0000;\">"+currentUsername+"</font>");
input.replace(QRegExp(pattern), "<font style=\" font-weight:600; color:#aa0000;\">"+username+"</font>");
return input;
}

QString AbstractChannel::userNameLink( const QString userName ) {
if( userName == currentUsername )
if( userName == ServerProfilesModel::getInstance()->getActiveProfile().userName() )
return userName;
QUrl url("qtlobby://query");
url.addQueryItem("username",userName);
Expand All @@ -332,3 +333,20 @@ void AbstractChannel::anchorClicked(QUrl url) {
QDesktopServices::openUrl(url);
}
}

void AbstractChannel::setChannelBrowser(ChannelTextBrowser* b) {
channelTextBrowser = b;
channelTextBrowser->setOpenLinks(false);
channelTextBrowser->setReadOnly( true );
QTextDocument * channelTextDocument = new QTextDocument( channelTextBrowser );
channelTextBrowser->setDocument( channelTextDocument );
}

void AbstractChannel::historyMessage( QDateTime time, QString message ) {
historyDateTime = time;
receiveCommand(Command(message));
}

void AbstractChannel::setHistoryMode(bool b) {
historyMode = b;
}
10 changes: 8 additions & 2 deletions src/AbstractChannel.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#include <QTextBrowser>
#include <QScrollBar>
#include <QTime>
#include <QDateTime>
#include <QGridLayout>
#include <QDesktopServices>

Expand All @@ -18,11 +19,14 @@ class AbstractChannel : public AbstractLobbyTab {
public:
AbstractChannel( QString name, QObject * parent = 0 );
virtual ~AbstractChannel();
static void setCurrentUsername(QString user);
void setChannelBrowser(ChannelTextBrowser* b);
void setHistoryMode(bool b);

public slots:
virtual void receiveInput( QString input ) = 0;
virtual void receiveCommand( Command command ) = 0;
virtual void historyMessage( QDateTime time, QString message );

protected:
void setActive( bool isActive );
virtual void setupUi( QWidget * tab );
Expand All @@ -40,8 +44,10 @@ public slots:
QIcon inactiveIcon;
QColor activeTextColor;
QColor inactiveTextColor;
static QString currentUsername;
QString userNameLink( const QString userName );

bool historyMode;
QDateTime historyDateTime;
protected slots:
void anchorClicked(QUrl url);
};
Expand Down
3 changes: 2 additions & 1 deletion src/AbstractLobbyTab.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,13 @@ AbstractLobbyTab::AbstractLobbyTab( QObject * parent ) {
isActive = false;
currentWidget = 0;
currentTabIndex = -1;
userNameCountryCodeMap = 0;
}
AbstractLobbyTab::~AbstractLobbyTab() {}

QString AbstractLobbyTab::flag( const QString userName ) {
QString flag = "<img width=\"16\" height=\"16\" src=\""+P("flags/%1.xpm")+"\" />&nbsp;";
if( Settings::Instance()->value("Chat/showFlags").toBool() )
if( Settings::Instance()->value("Chat/showFlags").toBool() && userNameCountryCodeMap )
if ( userNameCountryCodeMap->contains( userName ) )
return flag.arg( userNameCountryCodeMap->value( userName ) );
return "";
Expand Down
7 changes: 2 additions & 5 deletions src/BattleHostingDialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#include "BattleHostingDialog.h"
#include "ui_BattleHostingDialog.h"
#include "UnitSyncLib.h"
#include "ServerProfilesModel.h"

BattleHostingDialog::BattleHostingDialog(QProcess* spring, CommandAssigner* assigner, LobbyTabs* lobbyTabs, QWidget *parent) :
QDialog(parent),
Expand Down Expand Up @@ -39,7 +40,7 @@ void BattleHostingDialog::on_buttonBox_accepted() {
QMessageBox::critical(this, tr("Error"), tr("You have a battle running!\nClose it first!"));
return;
}
m_battleHost = new BattleHost(m_currentUsername, this);
m_battleHost = new BattleHost(ServerProfilesModel::getInstance()->getActiveProfile().userName(), this);
QString passwd = m_ui->passwordLineEdit->text();
m_battleHost->setHostingParams(0,
0,
Expand Down Expand Up @@ -74,10 +75,6 @@ void BattleHostingDialog::onClosed() {
m_battleHost = 0;
}

void BattleHostingDialog::setCurrentUsername(QString username) {
m_currentUsername = username;
}

void BattleHostingDialog::onReboot() {
UnitSyncLib* unitSyncLib = UnitSyncLib::getInstance();
m_ui->modComboBox->clear();
Expand Down
2 changes: 0 additions & 2 deletions src/BattleHostingDialog.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ class BattleHostingDialog : public QDialog {
public:
explicit BattleHostingDialog(QProcess* spring, CommandAssigner* assigner, LobbyTabs* lobbyTabs, QWidget *parent = 0);
virtual ~BattleHostingDialog();
void setCurrentUsername(QString username);

protected:
virtual void changeEvent(QEvent *e);
Expand All @@ -33,7 +32,6 @@ private slots:
BattleHost* m_battleHost;
CommandAssigner* m_assigner;
LobbyTabs* m_tabs;
QString m_currentUsername;
QProcess* m_spring;
};

Expand Down
Loading

0 comments on commit 0968d14

Please sign in to comment.