Exemple #1
0
void StatusLabel::setPict()
{
    const char *icon;
    const char *text;
    if (m_client->getState() == Client::Connecting){
        if (m_timer == NULL){
            m_timer = new QTimer(this);
            connect(m_timer, SIGNAL(timeout()), this, SLOT(timeout()));
            m_timer->start(1000);
            m_bBlink = false;
        }
        Protocol *protocol = m_client->protocol();
        text = I18N_NOOP("Connecting");
        unsigned status;
        if (m_bBlink){
            icon = "online";
            status = m_client->getManualStatus();
        }else{
            icon = "offline";
            status = STATUS_OFFLINE;
        }
        if (protocol){
            for (const CommandDef *cmd = protocol->statusList(); cmd->text; cmd++){
                if (cmd->id == status){
                    icon = cmd->icon;
                    break;
                }
            }
        }
    }else{
        if (m_timer){
            delete m_timer;
            m_timer = NULL;
        }
        if (m_client->getState() == Client::Error){
            icon = "error";
            text = I18N_NOOP("Error");
        }else{
            Protocol *protocol = m_client->protocol();
            const CommandDef *cmd = protocol->description();
            icon = cmd->icon;
            text = cmd->text;
            for (cmd = protocol->statusList(); cmd->text; cmd++){
                if (cmd->id == m_client->getStatus()){
                    icon = cmd->icon;
                    text = cmd->text;
                    break;
                }
            }
        }
    }
    QPixmap pict = Pict(icon);
    QString tip = CorePlugin::m_plugin->clientName(m_client);
    tip += "\n";
    tip += i18n(text);
    setPixmap(pict);
    QToolTip::add(this, tip);
    resize(pict.width(), pict.height());
    setFixedSize(pict.width(), pict.height());
};
Exemple #2
0
void NewProtocol::protocolChanged(int n)
{
    if (m_last){
        removePage(m_last);
        delete m_last;
        m_last = NULL;
    }
    if (m_connectWnd){
        removePage(m_connectWnd);
        delete m_connectWnd;
        m_connectWnd = NULL;
    }
    if (m_setup){
        removePage(m_setup);
        delete m_setup;
        m_setup = NULL;
    }
    if (m_client){
        delete m_client;
        m_client = NULL;
    }
    if ((n < 0) || (n >= (int)(m_protocols.size())))
        return;
    Protocol *protocol = m_protocols[n];
    m_client = protocol->createClient(NULL);
    if (m_client == NULL)
        return;
    m_setup = m_client->setupWnd();
    if (m_setup == NULL){
        delete m_client;
        m_client = NULL;
        return;
    }
    connect(m_setup, SIGNAL(okEnabled(bool)), this, SLOT(okEnabled(bool)));
    connect(this, SIGNAL(apply()), m_setup, SLOT(apply()));
    addPage(m_setup, i18n(protocol->description()->text));
    m_connectWnd = new ConnectWnd(m_bStart);
    addPage(m_connectWnd, i18n(protocol->description()->text));
    if (m_bStart){
        m_last = new QWidget;
        addPage(m_last, i18n(protocol->description()->text));
    }
    setNextEnabled(currentPage(), true);
    setIcon(Pict(protocol->description()->icon));
    Event e(EventRaiseWindow, this);
    e.process();
}
Exemple #3
0
NewProtocol::NewProtocol(QWidget *parent)
        : NewProtocolBase(parent, "new_protocol", true)
{
    m_setup  = NULL;
    m_client = NULL;
    m_last   = NULL;
    m_connectWnd = NULL;
    m_bConnected = false;
    m_bConnect = false;
    m_bStart   = (parent == NULL);
    SET_WNDPROC("protocol")
    setIcon(Pict("configure"));
    setButtonsPict(this);
    setCaption(caption());
    helpButton()->hide();
    for (unsigned n = 0;; n++){
        Event e(EventPluginGetInfo, (void*)n);
        pluginInfo *info = (pluginInfo*)e.process();
        if (info == NULL)
            break;
        if (info->info == NULL){
            Event e(EventLoadPlugin, info->name);
            e.process();
            if (info->info && !(info->info->flags & (PLUGIN_PROTOCOL & ~PLUGIN_NOLOAD_DEFAULT))){
                Event e(EventUnloadPlugin, info->name);
                e.process();
            }
        }
        if ((info->info == NULL) || !(info->info->flags & (PLUGIN_PROTOCOL & ~PLUGIN_NOLOAD_DEFAULT)))
            continue;
        info->bDisabled = false;
        Event eApply(EventApplyPlugin, info->name);
        eApply.process();
    }
    Protocol *protocol;
    ContactList::ProtocolIterator it;
    while ((protocol = ++it) != NULL){
        const CommandDef *cmd = protocol->description();
        if (cmd == NULL)
            continue;
        m_protocols.push_back(protocol);
    }
    sort(m_protocols.begin(), m_protocols.end(), cmp_protocol);
    for (unsigned i = 0; i < m_protocols.size(); i++){
        const CommandDef *cmd = m_protocols[i]->description();
        cmbProtocol->insertItem(Pict(cmd->icon), i18n(cmd->text));
    }
    connect(cmbProtocol, SIGNAL(activated(int)), this, SLOT(protocolChanged(int)));
    cmbProtocol->setCurrentItem(0);
    protocolChanged(0);
    connect(this, SIGNAL(selected(const QString&)), this, SLOT(pageChanged(const QString&)));
}
ConnectionSettings::ConnectionSettings(Client *client)
        : ConnectionSettingsBase(NULL, NULL, true)
{
    SET_WNDPROC("client")
    setButtonsPict(this);
    m_client = client;
    Protocol *protocol = client->protocol();
    const CommandDef *cmd = protocol->description();
    setIcon(Pict(cmd->icon));
    setCaption(i18n("Configure %1 client") .arg(i18n(cmd->text)));
    QVBoxLayout *lay = new QVBoxLayout(addWnd);
    QWidget *setupWnd = client->setupWnd();
    setupWnd->reparent(addWnd, QPoint());
    lay->addWidget(setupWnd);
    setupWnd->show();
}
ConnectionSettings::ConnectionSettings(Client *client) : QDialog(NULL)
        //: ConnectionSettingsBase(NULL, NULL, true)
{
	setupUi(this);
    SET_WNDPROC("client")
    setButtonsPict(this);
    m_client = client;
    Protocol *protocol = client->protocol();
    const CommandDef *cmd = protocol->description();
    setWindowIcon(Icon(cmd->icon));
    setWindowTitle(i18n("Configure %1 client") .arg(i18n(cmd->text)));
    QVBoxLayout *lay = new QVBoxLayout(addWnd);
    QWidget *setupWnd = client->setupWnd();
    setupWnd->setParent(addWnd);
    setupWnd->move(QPoint());
    lay->addWidget(setupWnd);
    setupWnd->show();
}
Exemple #6
0
void ConnectionManager::fill(Client *current)
{
    lstConnection->clear();
    QListWidgetItem *curItem = NULL;
    for (unsigned i = 0; i < getContacts()->nClients(); i++){
        Client *client = getContacts()->getClient(i);
        Protocol *protocol = client->protocol();
        const CommandDef *descr = protocol->description();
        QString text = CorePlugin::instance()->clientName(client);
        QListWidgetItem *item = new QListWidgetItem(text, lstConnection);
        if (descr)
            item->setIcon(Pict(descr->icon));
        if (current == client)
            curItem = item;
    }
    if (curItem)
        lstConnection->setCurrentItem(curItem);
    selectionChanged();
}
Exemple #7
0
void ConnectionManager::fill(Client *current)
{
    lstConnection->clear();
    QListViewItem *curItem = NULL;
    for (unsigned i = 0; i < getContacts()->nClients(); i++){
        Client *client = getContacts()->getClient(i);
        Protocol *protocol = client->protocol();
        const CommandDef *descr = protocol->description();
        QString text = CorePlugin::m_plugin->clientName(client);
        QListViewItem *item = new QListViewItem(lstConnection, text);
        if (descr)
            item->setPixmap(0, Pict(descr->icon, lstConnection->colorGroup().base()));
        if (current == client)
            curItem = item;
        QString index = QString::number(i);
        while (index.length() < 6)
            index = QString("0") + index;
        item->setText(1, index);
    }
    if (curItem)
        lstConnection->setCurrentItem(curItem);
    selectionChanged();
}
void ConfigureDialog::fill(unsigned id)
{
    lstBox->clear();
    lstBox->setSorting(1);

    ConfigItem *parentItem = new MainInfoItem(lstBox, 0);
    for (unsigned i = 0; i < getContacts()->nClients(); i++){
        Client *client = getContacts()->getClient(i);
        CommandDef *cmds = client->configWindows();
        if (cmds){
            parentItem = NULL;
            for (; cmds->text; cmds++){
                if (parentItem){
                    new ClientItem(parentItem, client, cmds);
                }else{
                    parentItem = new ClientItem(lstBox, client, cmds);
                    parentItem->setOpen(true);
                }
            }
        }
    }

    unsigned long n;
    parentItem = NULL;
    list<unsigned> st;
    for (n = 0; n < getContacts()->nClients(); n++){
        Protocol *protocol = getContacts()->getClient(n)->protocol();
        if ((protocol->description()->flags & (PROTOCOL_AR | PROTOCOL_AR_USER)) == 0)
            continue;
        if (parentItem == NULL){
            parentItem = new ConfigItem(lstBox, 0);
            parentItem->setText(0, i18n("Autoreply"));
            parentItem->setOpen(true);
        }
        for (const CommandDef *d = protocol->statusList(); d->text; d++){
            if (((protocol->description()->flags & PROTOCOL_AR_OFFLINE) == 0) &&
                    ((d->id == STATUS_ONLINE) || (d->id == STATUS_OFFLINE)))
                continue;
            list<unsigned>::iterator it;
            for (it = st.begin(); it != st.end(); ++it)
                if ((*it) == d->id)
                    break;
            if (it != st.end())
                continue;
            st.push_back(d->id);
            new ARItem(parentItem, d);
        }
    }

    parentItem = new ConfigItem(lstBox, 0);
    parentItem->setText(0, i18n("Plugins"));
    parentItem->setPixmap(0, Pict("run", lstBox->colorGroup().base()));
    parentItem->setOpen(true);

    for ( n = 0;; n++){
        Event e(EventPluginGetInfo, (void*)n);
        pluginInfo *info = (pluginInfo*)e.process();
        if (info == NULL) break;
        if (info->info == NULL){
            Event e(EventLoadPlugin, (char*)info->name.c_str());
            e.process();
        }
        if ((info->info == NULL) || (info->info->title == NULL)) continue;
        QString title = i18n(info->info->title);
        new PluginItem(parentItem, title, info, n);
    }

    QFontMetrics fm(lstBox->font());
    unsigned w = 0;
    for (QListViewItem *item = lstBox->firstChild(); item; item = item->nextSibling()){
        w = QMAX(w, itemWidth(item, fm));
    }
    lstBox->setFixedWidth(w);
    lstBox->setColumnWidth(0, w - 2);

    if (id){
        for (QListViewItem *item = lstBox->firstChild(); item; item = item->nextSibling()){
            if (setCurrentItem(item, id))
                return;
        }
    }
    lstBox->setCurrentItem(lstBox->firstChild());
}
Exemple #9
0
void *StatusFrame::processEvent(Event *e)
{
    CommandDef *cmd;
    switch (e->type()){
    case EventCheckState:
        cmd = (CommandDef*)(e->param());
        if ((cmd->menu_id == MenuStatusWnd) && (cmd->id == CmdStatusWnd)){
            unsigned n = 0;
            {
                QObjectList *l = queryList("StatusLabel");
                QObjectListIt itObject(*l);
                QObject *obj;
                while ((obj=itObject.current()) != NULL) {
                    ++itObject;
                    StatusLabel *lbl = static_cast<StatusLabel*>(obj);
                    if (lbl->x() + lbl->width() > width())
                        n++;
                }
                delete l;
            }
            CommandDef *cmds = new CommandDef[n + 1];
            memset(cmds, 0, sizeof(CommandDef) * (n + 1));
            QObjectList *l = queryList("StatusLabel");
            QObjectListIt itObject(*l);
            QObject *obj;
            n = 0;
            while ((obj=itObject.current()) != NULL) {
                ++itObject;
                StatusLabel *lbl = static_cast<StatusLabel*>(obj);
                if (lbl->x() + lbl->width() > width()){
                    cmds[n].id = 1;
                    cmds[n].text = "_";
                    cmds[n].text_wrk = strdup(CorePlugin::m_plugin->clientName(lbl->m_client).utf8());
                    cmds[n].popup_id = lbl->m_id;
                    if (lbl->m_client->getState() == Client::Error){
                        cmds[n].icon = "error";
                    }else{
                        Protocol *protocol = lbl->m_client->protocol();
                        const CommandDef *cmd = protocol->description();
                        cmds[n].icon = cmd->icon;
                        for (cmd = protocol->statusList(); cmd->text; cmd++){
                            if (cmd->id == lbl->m_client->getStatus()){
                                cmds[n].icon = cmd->icon;
                                break;
                            }
                        }
                    }
                    n++;
                }
            }
            delete l;
            cmd->param = cmds;
            cmd->flags |= COMMAND_RECURSIVE;
            return e->param();
        }
        break;
    case EventClientsChanged:
        addClients();
        break;
    case EventClientChanged:{
            StatusLabel *lbl = findLabel((Client*)(e->param()));
            if (lbl)
                lbl->setPict();
            break;
        }
    case EventClientError:
        if (isVisible()){
            clientErrorData *data = (clientErrorData*)(e->param());
            if (data->code == AuthError)
                break;
            StatusLabel *lbl = findLabel(data->client);
            if (lbl == NULL)
                break;
            if (data->err_str && *data->err_str){
                QString msg = i18n(data->err_str);
                if (data->args)
                    msg = msg.arg(QString::fromUtf8(data->args));
                raiseWindow(topLevelWidget());
                BalloonMsg::message(msg, lbl);
                return e->param();
            }
        }
        break;
    case EventIconChanged:{
            QObjectList *l = queryList("StatusLabel");
            QObjectListIt itObject(*l);
            QObject *obj;
            while ((obj=itObject.current()) != NULL) {
                ++itObject;
                static_cast<StatusLabel*>(obj)->setPict();
            }
            delete l;
            break;
        }
    }
    return NULL;
}
Exemple #10
0
void ConfigureDialog::fill(unsigned id)
{
    lstBox->clear();
    lstBox->sortItems(1, Qt::AscendingOrder);

    m_parentItem = new MainInfoItem(lstBox, 0);
    for (unsigned i = 0; i < getContacts()->nClients(); i++){
        Client *client = getContacts()->getClient(i);
        CommandDef *cmds = client->configWindows();
        if (cmds){
            m_parentItem = NULL;
            for (; !cmds->text.isEmpty(); cmds++){
                if (m_parentItem){
                    new ClientItem(m_parentItem, client, cmds);
                }else{
                    m_parentItem = new ClientItem(lstBox, client, cmds);
                    m_parentItem->setExpanded(true);
                }
            }
        }
    }

    unsigned long n;
    m_parentItem = NULL;
    list<unsigned> st;
    for (n = 0; n < getContacts()->nClients(); n++){
        Protocol *protocol = getContacts()->getClient(n)->protocol();
        if ((protocol->description()->flags & (PROTOCOL_AR | PROTOCOL_AR_USER)) == 0)
            continue;
        if (m_parentItem == NULL){
            m_parentItem = new ConfigItem(lstBox, 0);
            m_parentItem->setText(0, i18n("Autoreply"));
            m_parentItem->setExpanded(true);
        }
        for (const CommandDef *d = protocol->statusList(); !d->text.isEmpty(); d++){
            if (((protocol->description()->flags & PROTOCOL_AR_OFFLINE) == 0) &&
                    ((d->id == STATUS_ONLINE) || (d->id == STATUS_OFFLINE)))
                continue;
            list<unsigned>::iterator it;
            for (it = st.begin(); it != st.end(); ++it)
                if ((*it) == d->id)
                    break;
            if (it != st.end())
                continue;
            st.push_back(d->id);
            new ARItem(m_parentItem, d);
        }
    }

    m_parentItem = new ConfigItem(lstBox, 0);
    m_parentItem->setText(0, i18n("Plugins"));
    m_parentItem->setIcon(0, Pict("run"));
    m_parentItem->setExpanded(true);

    QStringList plugins = getPluginManager()->enumPlugins();
    foreach(QString plugin, plugins)
    {
        QString title = getPluginManager()->pluginTitle(plugin);
        if(title.isEmpty())
            continue;
        new PluginItem(m_parentItem, plugin, title, n);
    }