User::User(const UserId& id, bool temporary) : myId(id), m_bNotInList(temporary), myPrivate(new Private(this, id)) { LICQ_D(); // Cache protocol capabilities as a convenience Licq::ProtocolPlugin::Ptr protocol = Licq::gPluginManager.getProtocolPlugin(myId.protocolId()); myProtocolCapabilities = (protocol.get() != NULL ? protocol->capabilities() : 0); myProtocolStatuses = (protocol.get() != NULL ? protocol->statuses() : 0); myServerGroup = 0; if ((myProtocolCapabilities & ProtocolPlugin::CanSingleGroup) == 0) // Protocol handles multiple groups or no groups at all myServerGroup = -1; d->Init(); // Start building filename for user files string filename = "users/" + IniFile::sanitizeName(myId.ownerId().accountId()) + "." + Licq::protocolId_toString(myId.protocolId()); // Create owner specific dir if needed string dirname = gDaemon.baseDir() + filename.c_str(); if (mkdir(dirname.c_str(), 0700) < 0 && errno != EEXIST) gLog.error(tr("Failed to create directory %s: %s"), dirname.c_str(), strerror(errno)); // Add final parts to get filenames filename += "/" + IniFile::sanitizeName(myId.accountId()); d->myConf.setFilename(filename + ".conf"); d->myHistory.setFile(gDaemon.baseDir() + filename + ".history"); myPictureFileName = gDaemon.baseDir() + filename + ".picture"; if (m_bNotInList) { d->setDefaults(); return; } // Make sure we have a file so load won't fail if (!d->myConf.loadFile()) { d->myConf.setSection("user"); if (!d->myConf.writeFile()) gLog.error(tr("Error opening '%s' for writing."), d->myConf.filename().c_str()); d->setDefaults(); } else { d->myConf.setSection("user"); } d->loadUserInfo(); d->loadPictureInfo(); d->loadLicqInfo(); }
UserEventCommon::UserEventCommon(const Licq::UserId& userId, QWidget* parent, const char* name) : QWidget(parent), myHighestEventId(-1) { Support::setWidgetProps(this, name); setAttribute(Qt::WA_DeleteOnClose, true); myUsers.push_back(userId); { Licq::UserReadGuard user(userId); if (user.isLocked()) { myId = user->accountId().c_str(); myPpid = user->protocolId(); } } // Find out what's supported for the protocol mySendFuncs = 0; Licq::ProtocolPlugin::Ptr protocol = Licq::gPluginManager.getProtocolPlugin(myPpid); if (protocol.get() != NULL) mySendFuncs = protocol->capabilities(); myIsOwner = Licq::gUserManager.isOwner(myUsers.front()); myDeleteUser = false; myConvoId = 0; myTophLayout = new QHBoxLayout(this); myTopLayout = new QVBoxLayout(); myTophLayout->addLayout(myTopLayout); myTophLayout->setStretchFactor(myTopLayout, 1); QHBoxLayout* layt = new QHBoxLayout(); myTopLayout->addLayout(layt); myToolBar = new QToolBar(); myToolBar->setIconSize(QSize(16, 16)); layt->addWidget(myToolBar); layt->addStretch(1); myTimezone = new InfoField(true); myTimezone->setToolTip(tr("User's current local time")); int timezoneWidth = qMax(myTimezone->fontMetrics().width("88:88:88"), myTimezone->fontMetrics().width(tr("Unknown"))) + 10; myTimezone->setFixedWidth(timezoneWidth); myTimezone->setAlignment(Qt::AlignCenter); myTimezone->setFocusPolicy(Qt::ClickFocus); layt->addWidget(myTimezone); myMenu = myToolBar->addAction(tr("Menu"), this, SLOT(showUserMenu())); myMenu->setMenu(gUserMenu); if (myIsOwner) myMenu->setEnabled(false); myHistory = myToolBar->addAction(tr("History..."), this, SLOT(showHistory())); myInfo = myToolBar->addAction(tr("User Info..."), this, SLOT(showUserInfo())); myEncodingsMenu = new QMenu(this); myEncoding = myToolBar->addAction(tr("Encoding"), this, SLOT(showEncodingsMenu())); myEncoding->setMenu(myEncodingsMenu); if (!(mySendFuncs & Licq::ProtocolPlugin::CanVaryEncoding)) myEncoding->setVisible(false); myToolBar->addSeparator(); mySecure = myToolBar->addAction(tr("Secure Channel"), this, SLOT(switchSecurity())); if (!(mySendFuncs & Licq::ProtocolPlugin::CanSendSecure)) mySecure->setEnabled(false); myTimeTimer = NULL; myTypingTimer = NULL; QString userEncoding; { Licq::UserReadGuard u(myUsers.front()); if (u.isLocked()) { if (u->NewMessages() == 0) setWindowIcon(IconManager::instance()->iconForUser(*u)); else { setWindowIcon(IconManager::instance()->iconForEvent(Licq::UserEvent::TypeMessage)); flashTaskbar(); } updateWidgetInfo(*u); // restore prefered encoding userEncoding = u->userEncoding().c_str(); setTyping(u->isTyping()); } else { userEncoding = Licq::gUserManager.defaultUserEncoding().c_str(); } } myEncodingsGroup = new QActionGroup(this); connect(myEncodingsGroup, SIGNAL(triggered(QAction*)), SLOT(setEncoding(QAction*))); // populate the popup menu for (int i = 0; UserCodec::m_encodings[i].encoding != NULL; ++i) { UserCodec::encoding_t* it = &UserCodec::m_encodings[i]; bool currentCodec = it->encoding == userEncoding; if (!currentCodec && !Config::Chat::instance()->showAllEncodings() && !it->isMinimal) continue; QAction* a = new QAction(UserCodec::nameForEncoding(i), myEncodingsGroup); a->setCheckable(true); a->setData(i); if (currentCodec) a->setChecked(true); if (currentCodec && !Config::Chat::instance()->showAllEncodings() && !it->isMinimal) { // if the current encoding does not appear in the minimal list myEncodingsMenu->insertSeparator(myEncodingsMenu->actions()[0]); myEncodingsMenu->insertAction(myEncodingsMenu->actions()[0], a); } else { myEncodingsMenu->addAction(a); } } myPopupNextMessage = new QAction("Popup Next Message", this); addAction(myPopupNextMessage); connect(myPopupNextMessage, SIGNAL(triggered()), gLicqGui, SLOT(showNextEvent())); // We might be called from a slot so connect the signal only after all the // existing signals are handled. QTimer::singleShot(0, this, SLOT(connectSignal())); myMainWidget = new QVBoxLayout(); myMainWidget->setContentsMargins(0, 0, 0, 0); myTopLayout->addLayout(myMainWidget); updateIcons(); updateShortcuts(); connect(IconManager::instance(), SIGNAL(generalIconsChanged()), SLOT(updateIcons())); connect(Config::Shortcuts::instance(), SIGNAL(shortcutsChanged()), SLOT(updateShortcuts())); // Check if we want the window sticky if (!Config::Chat::instance()->tabbedChatting() && Config::Chat::instance()->msgWinSticky()) QTimer::singleShot(100, this, SLOT(setMsgWinSticky())); }