1
/***************************************************************************
3
* This program is free software; you can redistribute it and/or modify *
4
* it under the terms of the GNU General Public License as published by *
5
* the Free Software Foundation; either version 2 of the License, or *
6
* (at your option) any later version. *
8
***************************************************************************/
11
# include <QtGui/QMenu>
12
# include <QtGui/QMenuBar>
14
#include <QtCore/QStringList>
20
#include "config_file.h"
21
#include "custom_input.h"
22
#include "icons_manager.h"
23
#include "single_window.h"
25
extern "C" KADU_EXPORT int single_window_init(bool firstLoad)
29
singleWindowManager = new SingleWindowManager();
30
MainConfigurationWindow::registerUiFile(dataPath("kadu/modules/configuration/single_window.ui"),
36
extern "C" KADU_EXPORT void single_window_close()
40
MainConfigurationWindow::unregisterUiFile(dataPath("kadu/modules/configuration/single_window.ui"),
42
delete singleWindowManager;
43
singleWindowManager = NULL;
48
SingleWindowManager::SingleWindowManager()
50
singleWindow = new SingleWindow();
53
SingleWindowManager::~SingleWindowManager()
58
void SingleWindowManager::configurationUpdated()
60
int newRosterPos = config_file.readNumEntry("SingleWindow", "RosterPosition", 0);
61
if (singleWindow->rosterPosition() != newRosterPos)
63
singleWindow->changeRosterPos(newRosterPos);
67
SingleWindow::SingleWindow()
69
split = new QSplitter(Qt::Horizontal, this);
71
tabs = new QTabWidget(this);
72
tabs->setTabsClosable(true);
74
rosterPos = config_file.readNumEntry("SingleWindow", "RosterPosition", 0);
77
split->addWidget(kadu);
78
split->addWidget(tabs);
82
split->addWidget(tabs);
83
split->addWidget(kadu);
87
menuBar()->addMenu(kadu->mainMenu());
89
if (kadu->width() >= 250)
90
kadu->resize(250, kadu->height());
93
loadWindowGeometry(this, "SingleWindow", "WindowGeometry", 0, 0, 600, 600);
97
splitSizes.append(kadu->width());
98
splitSizes.append(width() - kadu->width());
102
splitSizes.append(width() - kadu->width());
103
splitSizes.append(kadu->width());
105
split->setSizes(splitSizes);
107
setWindowTitle(kadu->windowTitle());
109
connect(tabs, SIGNAL(tabCloseRequested(int)), this, SLOT(closeTab(int)));
110
connect(tabs, SIGNAL(currentChanged(int)), this, SLOT(onTabChange(int)));
112
connect(chat_manager, SIGNAL(handleNewChatWidget(ChatWidget *,bool &)),
113
this, SLOT(onNewChat(ChatWidget *,bool &)));
114
connect(chat_manager, SIGNAL(chatWidgetOpen(ChatWidget *)),
115
this, SLOT(onOpenChat(ChatWidget *)));
117
connect(kadu, SIGNAL(shown()), this, SLOT(show()));
118
connect(kadu, SIGNAL(hiding()), this, SLOT(hide()));
119
connect(kadu, SIGNAL(keyPressed(QKeyEvent *)), this, SLOT(onkaduKeyPressed(QKeyEvent *)));
120
connect(kadu, SIGNAL(statusPixmapChanged(const QIcon &, const QString &)),
121
this, SLOT(onStatusPixmapChanged(const QIcon &, const QString &)));
123
connect(userlist, SIGNAL(statusChanged(UserListElement, QString, const UserStatus &, bool, bool)),
124
this, SLOT(onStatusChanged(UserListElement)));
126
/* conquer all already open chats ;) */
127
ChatList chats = chat_manager->chats();
128
for (uint i = 0; i < chats.count(); i++)
130
ChatWidget* chat = chats[i];
132
chat->parent()->deleteLater();
134
chat->kaduRestoreGeometry();
141
SingleWindow::~SingleWindow()
143
split->setSizes(splitSizes);
145
saveWindowGeometry(this, "SingleWindow", "WindowGeometry");
147
disconnect(chat_manager, SIGNAL(handleNewChatWidget(ChatWidget *,bool &)),
148
this, SLOT(onNewChat(ChatWidget *,bool &)));
149
disconnect(chat_manager, SIGNAL(chatWidgetOpen(ChatWidget *)),
150
this, SLOT(onOpenChat(ChatWidget *)));
152
disconnect(tabs, SIGNAL(tabCloseRequested(int)), this, SLOT(closeTab(int)));
153
disconnect(tabs, SIGNAL(currentChanged(int)), this, SLOT(onTabChange(int)));
155
disconnect(kadu, SIGNAL(shown()), this, SLOT(show()));
156
disconnect(kadu, SIGNAL(hiding()), this, SLOT(hide()));
157
disconnect(kadu, SIGNAL(keyPressed(QKeyEvent *)), this, SLOT(onkaduKeyPressed(QKeyEvent *)));
158
disconnect(kadu, SIGNAL(statusPixmapChanged(const QIcon &, const QString &)),
159
this, SLOT(onStatusPixmapChanged(const QIcon &, const QString &)));
160
disconnect(userlist, SIGNAL(statusChanged(UserListElement, QString, const UserStatus &, bool, bool)),
161
this, SLOT(onStatusChanged(UserListElement)));
163
if (!Kadu::closing())
165
for (int i = tabs->count()-1; i >= 0; --i)
167
ChatWidget* chat = dynamic_cast<ChatWidget *>(tabs->widget(i));
168
UserListElements users = chat->users()->toUserListElements();
171
chat_manager->openPendingMsgs(users);
176
kadu->setParent(NULL);
177
loadWindowGeometry(kadu, "General", "Geometry", 0, 50, 205, 465);
180
void SingleWindow::changeRosterPos(int newRosterPos)
182
rosterPos = newRosterPos;
183
split->insertWidget(rosterPos, kadu);
186
void SingleWindow::onNewChat(ChatWidget *w, bool &handled)
192
void SingleWindow::onOpenChat(ChatWidget *w)
194
QStringList nicks = w->users()->altNicks();
195
QString title = nicks[0];
196
if (nicks.count() > 1)
197
title.append(", ...");
199
tabs->addTab(w, w->icon(), title);
200
tabs->setCurrentIndex(tabs->count()-1);
201
w->edit()->setFocus();
203
connect(w, SIGNAL(messageReceived(ChatWidget *)),
204
this, SLOT(onNewMessage(ChatWidget *)));
206
connect(w, SIGNAL(keyPressed(QKeyEvent*, ChatWidget*, bool&)),
207
this, SLOT(onChatKeyPressed(QKeyEvent*, ChatWidget*, bool&)));
210
void SingleWindow::closeTab(int index)
212
tabs->widget(index)->deleteLater();
213
tabs->removeTab(index);
216
void SingleWindow::closeEvent(QCloseEvent *event)
222
void SingleWindow::resizeEvent(QResizeEvent *event)
224
QSize newSize = event->size();
225
split->resize(newSize);
228
void SingleWindow::closeChatWidget(ChatWidget *w)
232
int index = tabs->indexOf(w);
238
void SingleWindow::onNewMessage(ChatWidget *w)
240
if (w != tabs->currentWidget())
242
int index = tabs->indexOf(w);
243
tabs->setTabIcon(index, icons_manager->loadIcon("Message"));
245
if (config_file.readBoolEntry("SingleWindow", "NumMessagesInTab", false))
247
QString title = tabs->tabText(index);
248
int pos = title.indexOf(" [");
251
title += QString(" [%1]").arg(w->newMessagesCount());
252
tabs->setTabText(index, title);
257
w->markAllMessagesRead();
261
void SingleWindow::onTabChange(int index)
266
ChatWidget *w = (ChatWidget *)tabs->widget(index);
267
tabs->setTabIcon(index, w->icon());
269
QString title = tabs->tabText(index);
270
int pos = title.indexOf(" [");
273
tabs->setTabText(index, title);
275
w->markAllMessagesRead();
278
void SingleWindow::onkaduKeyPressed(QKeyEvent *e)
280
/* unfortunatelly does not work correctly */
281
if (HotKey::shortCut(e, "ShortCuts", "FocusOnRosterTab"))
283
ChatWidget *w = (ChatWidget *)tabs->currentWidget();
286
w->edit()->setFocus();
291
void SingleWindow::onChatKeyPressed(QKeyEvent* e, ChatWidget* w, bool &handled)
293
/* workaround: we're receiving the same key event twice so ignore the duplicate */
294
static int duplicate = 0;
304
if (HotKey::shortCut(e, "ShortCuts", "SwitchTabLeft"))
306
int index = tabs->currentIndex();
309
tabs->setCurrentIndex(index-1);
313
else if (HotKey::shortCut(e, "ShortCuts", "SwitchTabRight"))
315
int index = tabs->currentIndex();
316
if (index < tabs->count())
318
tabs->setCurrentIndex(index+1);
322
else if (HotKey::shortCut(e, "ShortCuts", "HideShowRoster"))
324
QList<int> sizes = split->sizes();
325
if (sizes[rosterPos] != 0)
326
sizes[rosterPos] = 0;
329
split->setSizes(sizes);
332
else if (HotKey::shortCut(e, "ShortCuts", "FocusOnRosterTab"))
334
kadu->userBox()->setFocus();
339
void SingleWindow::onStatusPixmapChanged(const QIcon &icon, const QString &iconName)
344
void SingleWindow::onStatusChanged(UserListElement ule)
346
ChatWidget *chat = chat_manager->findChatWidget(ule);
347
int index = tabs->indexOf(chat);
350
chat->refreshTitle(); // the icon is not refreshed - refresh it
351
tabs->setTabIcon(index, chat->icon());
356
SingleWindowManager *singleWindowManager = NULL;