bool KviIdentityProfileSet::loadPrivate(KviConfigurationFile * pCfg, const QString & szPrefix, unsigned int uEntries) { if(m_pProfiles) m_pProfiles->clear(); else { m_pProfiles = new KviPointerList<KviIdentityProfile>; m_pProfiles->setAutoDelete(true); } if(uEntries != 0) { QString szTmp = QString("%1ProfilesEnabled").arg(szPrefix); m_bEnabled = pCfg->readBoolEntry(szTmp,false); for(unsigned int u = 0; u < uEntries; u++) { szTmp = QString("%1Profile%2_").arg(szPrefix,u); KviIdentityProfile * pProfile = new KviIdentityProfile(); if(!pProfile->load(pCfg,szTmp)) delete pProfile; else m_pProfiles->append(pProfile); } } if(m_pProfiles->isEmpty()) { m_bEnabled = false; delete m_pProfiles; m_pProfiles = 0; return false; } return true; }
void KviIdentityProfileSet::save(KviConfigurationFile * pCfg, const QString & szPrefix) { if(!m_pProfiles) return; if(m_pProfiles->isEmpty()) return; QString szTmp; if(m_bEnabled) { szTmp = QString("%1ProfilesEnabled").arg(szPrefix); pCfg->writeEntry(szTmp,m_bEnabled); } szTmp = QString("%1ProfilesNumber").arg(szPrefix); pCfg->writeEntry(szTmp,m_pProfiles->count()); int iIdx = 0; for(KviIdentityProfile * pProfile = m_pProfiles->first(); pProfile; pProfile = m_pProfiles->next()) { szTmp = QString("%1Profile%2_").arg(szPrefix).arg(iIdx); pProfile->save(pCfg,szTmp); iIdx++; } }
void KviIdentityProfileSet::copyFrom(const KviIdentityProfileSet & src) { if(src.m_pProfiles) { if(m_pProfiles) m_pProfiles->clear(); else { m_pProfiles = new KviPointerList<KviIdentityProfile>; m_pProfiles->setAutoDelete(true); } for(KviIdentityProfile * pSrcProfile = src.m_pProfiles->first(); pSrcProfile; pSrcProfile = src.m_pProfiles->next()) { KviIdentityProfile * pProfile = new KviIdentityProfile(); pProfile->copyFrom(*pSrcProfile); m_pProfiles->append(pProfile); } if(m_pProfiles->isEmpty()) { m_bEnabled = false; delete m_pProfiles; m_pProfiles = 0; } else { m_bEnabled = src.m_bEnabled; } } else { m_bEnabled = false; if(m_pProfiles) { delete m_pProfiles; m_pProfiles = 0; } } }
KviIdentityProfile * KviIdentityProfileSet::findNetwork(const QString & szNetwork) { if(!m_pProfiles) return 0; KviIdentityProfile * pProfile; for(pProfile = m_pProfiles->first(); pProfile; pProfile = m_pProfiles->next()) { if(KviQString::matchString(pProfile->network(),szNetwork,false,true)) return pProfile; } return 0; }
void OptionsWidget_identityProfile::commit() { KviIdentityProfileSet::instance()->clear(); if(m_pTreeWidget->topLevelItemCount()) { KviIdentityProfileSet::instance()->setEnabled(m_pProfilesCheck->isChecked()); QTreeWidgetItem * pItem; for(int i=0; i < m_pTreeWidget->topLevelItemCount(); i++) { pItem = (QTreeWidgetItem *)m_pTreeWidget->topLevelItem(i); KviIdentityProfile * pProfile = new KviIdentityProfile(); pProfile->setName(pItem->text(0)); pProfile->setNetwork(pItem->text(1)); pProfile->setNick(pItem->text(2)); pProfile->setAltNick(pItem->text(3)); pProfile->setUserName(pItem->text(4)); pProfile->setRealName(pItem->text(5)); KviIdentityProfileSet::instance()->addProfile(pProfile); } } KviOptionsWidget::commit(); }
void OptionsWidget_identityProfile::addProfileEntry() { KviIdentityProfile profile; m_iCurrentEditedProfile = -1; if(m_pEditor) delete m_pEditor; m_pEditor = new IdentityProfileEditor(this); if(m_pEditor->editProfile(&profile)) { QTreeWidgetItem * pItem = new QTreeWidgetItem(m_pTreeWidget); pItem->setText(0,profile.name()); pItem->setText(1,profile.network()); pItem->setText(2,profile.nick()); pItem->setText(3,profile.altNick()); pItem->setText(4,profile.userName()); pItem->setText(5,profile.realName()); } }
void OptionsWidget_identityProfile::editProfileEntry() { QTreeWidgetItem * pItem = (QTreeWidgetItem *)m_pTreeWidget->currentItem(); if(!pItem) return; // Fill in the editor data KviIdentityProfile profile; profile.setName(pItem->text(0)); profile.setNetwork(pItem->text(1)); profile.setNick(pItem->text(2)); profile.setAltNick(pItem->text(3)); profile.setUserName(pItem->text(4)); profile.setRealName(pItem->text(5)); m_iCurrentEditedProfile=m_pTreeWidget->indexOfTopLevelItem(pItem); if(m_pEditor) delete m_pEditor; m_pEditor = new IdentityProfileEditor(this); if(m_pEditor->editProfile(&profile)) { pItem->setText(0,profile.name()); pItem->setText(1,profile.network()); pItem->setText(2,profile.nick()); pItem->setText(3,profile.altNick()); pItem->setText(4,profile.userName()); pItem->setText(5,profile.realName()); } }
OptionsWidget_identityProfile::OptionsWidget_identityProfile(QWidget * pParent) : KviOptionsWidget(pParent) { setObjectName("identity_profiles_option_widget"); m_pEditor = 0; m_iCurrentEditedProfile = -1; createLayout(); QGridLayout * pLayout = layout(); KviIdentityProfileSet * pSet = KviIdentityProfileSet::instance(); bool bEnabled = pSet ? (pSet->isEnabled() && !pSet->isEmpty()) : false; m_pProfilesCheck = new QCheckBox(__tr2qs_ctx("Enable Network Profiles","options"),this); KviTalToolTip::add(m_pProfilesCheck,__tr2qs_ctx("This check enables the use of network profiles","options")); m_pProfilesCheck->setChecked(bEnabled); pLayout->addWidget(m_pProfilesCheck,0,0,1,3); connect(m_pProfilesCheck,SIGNAL(toggled(bool)),this,SLOT(toggleControls())); // Profiles list m_pTreeWidget = new QTreeWidget(this); m_pTreeWidget->setSelectionMode(QAbstractItemView::SingleSelection); m_pTreeWidget->setAllColumnsShowFocus(true); QStringList labels; labels.append(__tr2qs_ctx("Name","options")); labels.append(__tr2qs_ctx("Network","options")); labels.append(__tr2qs_ctx("Nickname","options")); labels.append(__tr2qs_ctx("Alt. Nick","options")); labels.append(__tr2qs_ctx("Username","options")); labels.append(__tr2qs_ctx("Realname","options")); m_pTreeWidget->setHeaderLabels(labels); KviTalToolTip::add(m_pTreeWidget, \ __tr2qs_ctx("<center>This is a set of rules to use profiles." \ "KVIrc will use them to handle the user connection " \ "data before the data is sent to the IRC server.<br>" \ "This is useful if a user wants to use different data " \ "on different networks without changing them at every " \ "connection attempt.","options")); pLayout->addWidget(m_pTreeWidget,1,0,1,3); connect(m_pTreeWidget,SIGNAL(itemSelectionChanged()),this,SLOT(toggleControls())); // Buttons box KviTalHBox * pBtnBox = new KviTalHBox(this); pLayout->addWidget(pBtnBox,2,0); m_pBtnAddProfile = new QPushButton(__tr2qs_ctx("Add Profile","options"),pBtnBox); connect(m_pBtnAddProfile,SIGNAL(clicked()),this,SLOT(addProfileEntry())); m_pBtnEditProfile = new QPushButton(__tr2qs_ctx("Edit Profile","options"),pBtnBox); connect(m_pBtnEditProfile,SIGNAL(clicked()),this,SLOT(editProfileEntry())); m_pBtnDelProfile = new QPushButton(__tr2qs_ctx("Delete Profile","options"),pBtnBox); connect(m_pBtnDelProfile,SIGNAL(clicked()),this,SLOT(delProfileEntry())); // Fill in the treewidget if(pSet && pSet->profiles()) { QTreeWidgetItem * pItem; KviPointerList<KviIdentityProfile> * pList = pSet->profiles(); for(KviIdentityProfile * pProfile = pList->first(); pProfile; pProfile = pList->next()) { pItem = new QTreeWidgetItem(m_pTreeWidget); pItem->setText(0,pProfile->name()); pItem->setText(1,pProfile->network()); pItem->setText(2,pProfile->nick()); pItem->setText(3,pProfile->altNick()); pItem->setText(4,pProfile->userName()); pItem->setText(5,pProfile->realName()); } } toggleControls(); }