QMimeData* SessionItemModel::mimeData(const QModelIndexList& indexes) const { QByteArray itemIdArray; QDataStream itemIdStream(&itemIdArray, QIODevice::WriteOnly); for (int i = 0; i < indexes.count(); ++i) { QModelIndex index = indexes[i]; if (index.isValid() == true) { SessionItem* pItem = index.data(SessionItemModel::SessionItemRole).value<SessionItem*>(); if (pItem != NULL) { QString itemId = QString::fromStdString(pItem->getId()); if (itemId.isEmpty() == false) { itemIdStream << itemId; } } } } QMimeData* pData = QAbstractItemModel::mimeData(indexes); if (pData != NULL) { pData->setData("application/x-sessionitem-id", itemIdArray); pData->setData("application/x-sessionitem", itemIdArray); // Deprecated pData->setData("text/x-session-id", itemIdArray); // Deprecated } return pData; }
SessionManager::~SessionManager() { save(); foreach(QObject * item, m_items) { SessionItem* sessionItem = static_cast<SessionItem*>(item); sessionItem->session()->quit(m_appName); delete sessionItem; }
void SessionList::OnUserPhotoReady(PhotoType type, const std::string& accid, const std::wstring &photo_path) { if (type == kUser || type == kTeam) { SessionItem* item = (SessionItem*)session_list_->FindSubControl(nbase::UTF8ToUTF16(accid)); if (item) item->FindSubControl(L"head_image")->SetBkImage(photo_path); } }
void SessionList::ResetUnreadCount(const std::string &id) { std::wstring wid = nbase::UTF8ToUTF16(id); SessionItem* item = dynamic_cast<SessionItem*>(session_list_->FindSubControl(wid)); if (item) { item->ResetUnread(); InvokeUnreadCountChange(); } }
int SessionList::AdjustMsg(const nim::SessionData &msg) { int count = session_list_->GetCount(); for (int i = 0; i < count; i++) { SessionItem* item = dynamic_cast<SessionItem*>(session_list_->GetItemAt(i)); if (item) { if (msg.msg_timetag_ == 0 || msg.msg_timetag_ > item->GetMsgTime()) return i; } } return -1; }
void SessionList::InvokeUnreadCountChange() { if (unread_count_change_cb_list_.empty()) return; int unread_count = sys_msg_unread_ + custom_msg_unread_; int count = session_list_->GetCount(); for (int i = 0; i < count; i++) { SessionItem* item = dynamic_cast<SessionItem*>(session_list_->GetItemAt(i)); if (item) { unread_count += item->GetUnread(); } } for (auto& it : unread_count_change_cb_list_) (*(it.second))(unread_count); }
void PlugInModel::removePlugIn(Subject& subject, const string& signal, const boost::any& value) { PlugIn* pPlugIn = boost::any_cast<PlugIn*>(value); SessionItem* pItem = dynamic_cast<SessionItem*>(pPlugIn); if (pItem != NULL) { string plugInName = pItem->getName(); PlugInDescriptor* pDescriptor = mpManager->getPlugInDescriptor(plugInName); if (pDescriptor != NULL) { SessionItemWrapper* pDescriptorWrapper = getWrapper(pDescriptor); if (pDescriptorWrapper != NULL) { pDescriptorWrapper->removeChild(pItem); } } } }
SessionItem* SessionList::AddSessionItem(const nim::SessionData &item_data) { SessionItem* item = dynamic_cast<SessionItem*>(session_list_->FindSubControl(nbase::UTF8ToUTF16(item_data.id_))); nim::SessionData item_data_new = item_data; if (item) { if (nim::kNIMSessionCommandMsgDeleted != item_data.command_ && item->GetMsgTime() > item_data.msg_timetag_) { item_data_new = item->GetSessionData(); item_data_new.unread_count_ = item_data.unread_count_; } } int index = AdjustMsg(item_data_new); if (item && (session_list_->GetItemIndex(item) == index - 1 || session_list_->GetItemIndex(item) == index)) { item->InitMsg(item_data_new); //应该插入自己紧靠前面或后面的位置,就不用删除,直接更新。 } else { if (item) session_list_->Remove(item); item = new SessionItem; GlobalManager::FillBoxWithCache(item, L"main/session_item.xml"); index = AdjustMsg(item_data_new); //删掉之后重新算一次 if (index >= 0) session_list_->AddAt(item, index); else session_list_->Add(item); item->InitCtrl(); item->InitMsg(item_data_new); item->AttachAllEvents(nbase::Bind(&SessionList::OnItemNotify, this, std::placeholders::_1)); } InvokeUnreadCountChange(); return item; }
SessionItem * SliderFactory::loadItem(KConfigBase * configGroup) { SessionItem * retVal = new Slider(configGroup->group()); retVal->restore(configGroup); return retVal; }
ExportOptionsDlg::ExportOptionsDlg(ExporterResource& pExporter, QWidget* pParent) : QDialog(pParent), mpExporter(pExporter), mpTabWidget(NULL), mpSubsetPage(NULL), mpExporterPage(NULL) { // Options widget QStackedWidget* pStack = new QStackedWidget(this); // Subset page RasterElement* pRasterElement = dynamic_cast<RasterElement*>(mpExporter->getItem()); RasterFileDescriptor* pRasterWholeCubeFileDescriptor = NULL; RasterDataDescriptor* pRasterOrgDataDescriptor = NULL; if (pRasterElement != NULL) { pRasterOrgDataDescriptor = dynamic_cast<RasterDataDescriptor*>(pRasterElement->getDataDescriptor()); if (pRasterOrgDataDescriptor != NULL) { // we are creating a file descriptor for export from the original cube, because the SubsetWidget // uses DimensionDescriptor::operator= compare's to determine selection which dictate that on-disk, // original and active numbers need to be identical, this guarantees that DimensionDescriptors will // compare correctly. pRasterWholeCubeFileDescriptor = dynamic_cast<RasterFileDescriptor*>( RasterUtilities::generateFileDescriptorForExport(pRasterOrgDataDescriptor, "foobar")); } } RasterFileDescriptor* pRasterFileDescriptor = dynamic_cast<RasterFileDescriptor*>(mpExporter->getFileDescriptor()); if ((pRasterFileDescriptor != NULL) && (pRasterWholeCubeFileDescriptor != NULL) && (pRasterOrgDataDescriptor != NULL)) { mpSubsetPage = new SubsetWidget(); mpSubsetPage->setExportMode(true); // Rows const vector<DimensionDescriptor>& orgRows = pRasterWholeCubeFileDescriptor->getRows(); const vector<DimensionDescriptor>& selectedRows = pRasterFileDescriptor->getRows(); mpSubsetPage->setRows(orgRows, selectedRows); // Columns const vector<DimensionDescriptor>& orgColumns = pRasterWholeCubeFileDescriptor->getColumns(); const vector<DimensionDescriptor>& selectedColumns = pRasterFileDescriptor->getColumns(); mpSubsetPage->setColumns(orgColumns, selectedColumns); // Bands const vector<DimensionDescriptor>& orgBands = pRasterWholeCubeFileDescriptor->getBands(); const vector<DimensionDescriptor>& selectedBands = pRasterFileDescriptor->getBands(); vector<string> bandNames = RasterUtilities::getBandNames(pRasterOrgDataDescriptor); mpSubsetPage->setBands(orgBands, bandNames, selectedBands); // Initial bad band file directory QString strDirectory; string filename = pRasterFileDescriptor->getFilename(); if (filename.empty() == false) { QFileInfo fileInfo(QString::fromStdString(filename)); strDirectory = fileInfo.absolutePath(); } mpSubsetPage->setBadBandFileDirectory(strDirectory); } // Exporter page if (mpExporter->getPlugIn() != NULL) { mpExporterPage = mpExporter->getExportOptionsWidget(); } // Horizontal line QFrame* pLine = new QFrame(this); pLine->setFrameStyle(QFrame::HLine | QFrame::Sunken); // Buttons QDialogButtonBox* pButtonBox = new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel, Qt::Horizontal, this); // Layout QVBoxLayout* pLayout = new QVBoxLayout(this); pLayout->setMargin(10); pLayout->setSpacing(10); pLayout->addWidget(pStack, 10); pLayout->addWidget(pLine); pLayout->addWidget(pButtonBox); // Initialization QString strWindowTitle = "Export Options"; SessionItem* pSessionItem = mpExporter->getItem(); if (pSessionItem != NULL) { string name = pSessionItem->getDisplayName(); if (name.empty() == true) { name = pSessionItem->getName(); } if (name.empty() == false) { strWindowTitle += ": " + QString::fromStdString(name); } } setWindowTitle(strWindowTitle); setModal(true); if ((mpSubsetPage != NULL) || (mpExporterPage != NULL)) { QWidget* pSubsetWidget = NULL; if (mpSubsetPage != NULL) { pSubsetWidget = new QWidget(); mpSubsetPage->setParent(pSubsetWidget); QVBoxLayout* pSubsetLayout = new QVBoxLayout(pSubsetWidget); if (mpExporterPage != NULL) { pSubsetLayout->setMargin(10); } else { pSubsetLayout->setMargin(0); } pSubsetLayout->setSpacing(10); pSubsetLayout->addWidget(mpSubsetPage); } QWidget* pExporterWidget = NULL; if (mpExporterPage != NULL) { pExporterWidget = new QWidget(); mpExporterPage->setParent(pExporterWidget); QVBoxLayout* pExporterLayout = new QVBoxLayout(pExporterWidget); if (mpSubsetPage != NULL) { pExporterLayout->setMargin(10); } else { pExporterLayout->setMargin(0); } pExporterLayout->setSpacing(10); pExporterLayout->addWidget(mpExporterPage); } if ((pSubsetWidget != NULL) && (pExporterWidget != NULL)) { QString strExporterCaption = mpExporterPage->windowTitle(); if (strExporterCaption.isEmpty() == true) { PlugIn* pPlugIn = mpExporter->getPlugIn(); if (pPlugIn != NULL) { strExporterCaption = QString::fromStdString(pPlugIn->getName()); } if (strExporterCaption.isEmpty() == true) { strExporterCaption = "Exporter"; } } mpTabWidget = new QTabWidget(this); mpTabWidget->setTabPosition(QTabWidget::North); mpTabWidget->addTab(pSubsetWidget, "Subset"); mpTabWidget->addTab(pExporterWidget, strExporterCaption); pStack->addWidget(mpTabWidget); } else if (pSubsetWidget != NULL) { pStack->addWidget(pSubsetWidget); pButtonBox->setStandardButtons(QDialogButtonBox::Ok | QDialogButtonBox::Cancel); } else if (pExporterWidget != NULL) { pStack->addWidget(pExporterWidget); } } if (pStack->count() == 0) { QLabel* pNoOptionsLabel = new QLabel("No options are available", this); pNoOptionsLabel->setAlignment(Qt::AlignCenter); pNoOptionsLabel->setMinimumSize(250, 100); pStack->addWidget(pNoOptionsLabel); } // Connections VERIFYNR(connect(pButtonBox, SIGNAL(accepted()), this, SLOT(accept()))); VERIFYNR(connect(pButtonBox, SIGNAL(rejected()), this, SLOT(reject()))); }
QVariant SessionItemModel::data(const QModelIndex& index, int role) const { if (index.isValid() == false) { return QVariant(); } SessionItemWrapper* pWrapper = reinterpret_cast<SessionItemWrapper*>(index.internalPointer()); if (pWrapper != NULL) { SessionItem* pItem = pWrapper->getSessionItem(); if (role == Qt::CheckStateRole) { if (flags(index) & Qt::ItemIsUserCheckable) { Qt::CheckState checkState = pWrapper->getCheckState(); return QVariant(checkState); } } else if (role == Qt::DecorationRole) { if (pItem != NULL) { const QIcon& itemIcon = pItem->getIcon(); return QVariant(itemIcon); } } else if (role == Qt::DisplayRole || role == Qt::EditRole) { QString strItemName = pWrapper->getDisplayName(); if ((strItemName.isEmpty() == true) && (pItem != NULL)) { string itemName = pItem->getDisplayName(); if (itemName.empty() == true) { itemName = pItem->getName(); } strItemName = QString::fromStdString(itemName); } if (strItemName.isEmpty() == false) { return QVariant(strItemName); } } else if (role == Qt::FontRole) { QFont itemFont = pWrapper->getDisplayFont(); return QVariant(itemFont); } else if (role == Qt::ForegroundRole) { QColor itemColor = pWrapper->getDisplayColor(); return QVariant(itemColor); } else if (role == Qt::BackgroundRole) { QColor itemColor = pWrapper->getBackgroundColor(); return QVariant(itemColor); } else if (role == Qt::ToolTipRole) { if (pItem != NULL) { const string& displayText = pItem->getDisplayText(); if (displayText.empty() == false) { return QVariant(QString::fromStdString(displayText)); } } } else if (role == SessionItemModel::SessionItemRole) { return QVariant::fromValue(pItem); } } return QVariant(); }
void SessionList::OnTeamNameChange(const nim::TeamInfo& team_info) { SessionItem* item = (SessionItem*)session_list_->FindSubControl(nbase::UTF8ToUTF16(team_info.GetTeamID())); if (item) ((Label*)item->FindSubControl(L"label_name"))->SetUTF8Text(team_info.GetName()); }
void SessionList::OnSessionChangeCallback(nim::NIMResCode rescode, const nim::SessionData& data, int total_unread_counts) { if (rescode != nim::kNIMResSuccess) { QLOG_APP(L"SessionList::OnChangeCallback Error! {0}, uid:{1}, unread_count: {2}") << rescode << data.id_<< total_unread_counts; assert(0); return; } QLOG_APP(L"SessionList::OnChangeCallback. command: {0}, uid: {1}, type: {2}, total unread_count: {3}") << data.command_ << data.id_ << data.type_ << total_unread_counts; switch (data.command_) { case nim::kNIMSessionCommandAdd: case nim::kNIMSessionCommandUpdate: case nim::kNIMSessionCommandMsgDeleted: { if (data.last_updated_msg_) { AddSessionItem(data); if (SessionManager::GetInstance()->IsSessionBoxActive(data.id_)) { ResetUnreadCount(data.id_); } } } break; case nim::kNIMSessionCommandRemoveAll: RemoveAllSessionItem(); break; case nim::kNIMSessionCommandRemoveAllP2P: case nim::kNIMSessionCommandRemoveAllTeam: { for (int i = session_list_->GetCount() - 1; i >= 0; i--) { SessionItem* item = dynamic_cast<SessionItem*>(session_list_->GetItemAt(i)); if (item && (item->GetIsTeam() == (data.command_ == nim::kNIMSessionCommandRemoveAllTeam))) { session_list_->RemoveAt(i); } } } break; case nim::kNIMSessionCommandRemove: break; case nim::kNIMSessionCommandAllMsgDeleted: case nim::kNIMSessionCommandAllP2PMsgDeleted: case nim::kNIMSessionCommandAllTeamMsgDeleted: { for (int i = session_list_->GetCount() - 1; i >= 0; i--) { SessionItem* item = dynamic_cast<SessionItem*>(session_list_->GetItemAt(i)); if (item) { if (data.command_ == nim::kNIMSessionCommandAllMsgDeleted || (item->GetIsTeam() == (data.command_ == nim::kNIMSessionCommandAllTeamMsgDeleted))) { item->ClearMsg(); } } } } break; } }
ExportDlg::ExportDlg(ExporterResource& pExporter, const vector<PlugInDescriptor*>& availablePlugins, QWidget* pParent) : FilePlugInDlg(availablePlugins, ConfigurationSettings::getSettingPluginWorkingDirectoryKey("Exporter"), pParent), mpExporter(pExporter), mValidated(false) { // Initializtion setWindowTitle("Export"); setFileMode(QFileDialog::AnyFile); setAcceptMode(QFileDialog::AcceptSave); setConfirmOverwrite(true); setLabelText(QFileDialog::LookIn, "Save in:"); setPlugInLabel("Exporter"); enableOptions(true); // Set the initial directory Service<ConfigurationSettings> pSettings; const Filename* pWorkingDir = pSettings->getSetting( ConfigurationSettings::getSettingPluginWorkingDirectoryKey("Exporter")).getPointerToValue<Filename>(); if (pWorkingDir == NULL) { pWorkingDir = ConfigurationSettings::getSettingExportPath(); } string directory; if (pWorkingDir != NULL) { directory = pWorkingDir->getFullPathAndName(); } if (!directory.empty()) { setDirectory(QString::fromStdString(directory)); } if (isDefaultPlugIn()) { setSelectedPlugIn("Ice Exporter"); } updateFromExporter(getSelectedPlugIn()); // Set the initially selected file QString strFilename; SessionItem* pSessionItem = mpExporter->getItem(); if (pSessionItem != NULL) { DataElement* pDataElement = dynamic_cast<DataElement*>(pSessionItem); if (pDataElement != NULL) { strFilename = QString::fromStdString(pDataElement->getFilename()); } if (strFilename.isEmpty() == true) { strFilename = QString::fromStdString(pSessionItem->getName()); } strFilename = updateExtension(strFilename); selectFile(strFilename); } updateFromFile(strFilename); // Connections VERIFYNR(connect(this, SIGNAL(plugInSelected(const QString&)), this, SLOT(updateFromExporter(const QString&)))); VERIFYNR(connect(this, SIGNAL(optionsClicked()), this, SLOT(invokeOptionsDialog()))); }