1 /* coded by Ketmar // Vampire Avalon (psyc://ketmar.no-ip.org/~Ketmar)
2 * Understanding is not required. Only obedience.
4 * This program is free software. It comes without any warranty, to
5 * the extent permitted by applicable law. You can redistribute it
6 * and/or modify it under the terms of the Do What The Fuck You Want
7 * To Public License, Version 2, as published by Sam Hocevar. See
8 * http://sam.zoy.org/wtfpl/COPYING for more details.
22 #include "psyccontact.h"
25 extern bool debugOutput
;
28 ///////////////////////////////////////////////////////////////////////////////
29 FloatersManager::FloatersManager (ChatForm
*mCForm
, int titleBlinkTO
, int msgBlinkTO
) :
30 FloatWinManager(titleBlinkTO
, msgBlinkTO
, mCForm
), mForm(mCForm
)
37 FloatersManager::~FloatersManager () {
39 foreach (QIcon
*i
, mIconCache
) delete i
;
42 QHash
<PsycProto::Status
, QIcon
*> mIconCache
;
46 const QIcon
*FloatersManager::getStatusIcon (FloatingWindow
*sender
, PsycProto::Status status
) {
48 if (!mIconCache
[status
]) {
49 QIcon
*i
= new QIcon(mForm
->statusIcon(status
));
50 mIconCache
[status
] = i
;
52 return mIconCache
[status
];
56 const QIcon
*FloatersManager::getMsgIcon (FloatingWindow
*sender
) {
58 if (!mMsgIcon
) mMsgIcon
= new QIcon(MSG_TRAY_ICON
);
63 static void dsSaveString (QDataStream
&st
, const QString
&s
) {
64 QByteArray
ba(s
.toUtf8());
67 for (int f
= 0; f
< ba
.size(); f
++) st
<< (quint8
)(ba
.at(f
));
71 static QString
dsLoadString (QDataStream
&st
) {
75 for (int f
= 0; f
< len
; f
++) {
80 return QString::fromUtf8(ba
);
84 static QString
toAscii85BA (const QByteArray
&ba
) {
86 K8ASCII85::encode(res
, ba
);
87 return QString::fromAscii(res
);
91 static QByteArray
fromAscii85BA (const QString
&s
) {
93 QByteArray
ba(s
.toAscii());
94 K8ASCII85::decode(res
, ba
);
99 void FloatersManager::saveFState () const {
100 if (!mList
.count()) {
101 mForm
->setOpt("/floaty/*state", "");
107 QDataStream
st(&ba
, QIODevice::WriteOnly
);
108 st
<< (quint8
)0; // version
111 int sz
= mList
.size();
113 QHash
<QString
, FloatingWindow
*>::const_iterator i
;
114 for (i
= mList
.begin(); i
!= mList
.end(); ++i
) {
115 dsSaveString(st
, i
.key());
116 (*i
)->saveFState(st
);
120 //for (int f = 0; f < ba.size(); f++) fprintf(stderr, "%02X ", (quint8)(ba.at(f))); fprintf(stderr, "\n");
122 QString
o(toAscii85BA(ba
));
123 //fprintf(stderr, "%s\n", o.toAscii().constData());
125 mForm
->setOpt("/floaty/*state", o
);
129 void FloatersManager::loadFState () {
131 QString
s(mForm
->toStringOpt("/floaty/*state"));
132 //fprintf(stderr, "%s\n", s.toAscii().constData());
134 QByteArray
ba(fromAscii85BA(s
));
136 //for (int f = 0; f < ba.size(); f++) fprintf(stderr, "%02X ", (quint8)(ba.at(f))); fprintf(stderr, "\n");
138 QDataStream
st(&ba
, QIODevice::ReadOnly
);
141 if (ver
!= 0) return; // invalid version
145 //qDebug() << " " << sz << "items";
147 QString
uniS(dsLoadString(st
));
148 //qDebug() << " " << uniS;
149 FloatingWindow
*w
= produce(uniS
, "", "", PsycProto::Offline
);
150 if (!w
) return; // error!
151 w
->restoreFState(st
);
152 PsycContact
*cc
= mForm
->findContact(uniS
);
153 if (!cc
|| cc
->isPlace()) {
154 qDebug() << " no such contact!";
157 //qDebug() << " *" << cc->uni() << cc->verbatim();
158 newTitle(cc
->uni(), cc
->verbatim());
159 newTip(cc
->uni(), cc
->uni());