Changeset 178


Ignore:
Timestamp:
03/23/09 10:03:35 (3 years ago)
Author:
antonbatenev.ya.ru
Message:

выброшен весь код из виджета отображения дерева сообщений

Location:
branches/message_tree
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • branches/message_tree/message_tree.cpp

    r177 r178  
    55// $URL$ 
    66//---------------------------------------------------------------------------------------------- 
    7 #include "parser.h" 
    8 #include "global.h" 
    9 #include "model/all.h" 
     7#include "message_tree.h" 
    108#include "icon_effect.h" 
    11 #include "form_source.h" 
    12 #include "form_message.h" 
    13 #include "form_moderate.h" 
    14 #include "message_tree.h" 
    15 #include "tree_widget_item.h" 
    16 #include "storage/storage_factory.h" 
    17 //---------------------------------------------------------------------------------------------- 
    18 /*! 
    19  * \brief Элемент, который хранится в каждой ноде дерева 
    20  */ 
    21 typedef struct AMessageInfoGUI 
    22 { 
    23         ATopicInfo Info;             /*!< \brief Дескриптор сообщения */ 
    24         bool       IsInfoLoaded;     /*!< \brief Флаг наличия загрузки информации (актуально только для топиков) */ 
    25         bool       IsChildLoaded;    /*!< \brief Флаг того, что загружены дочерние сообщения (актуально только для топиков) */ 
    26         int        UnreadChildCount; /*!< \brief Количество непрочитанных дочерних сообщений */ 
    27         bool       IsBodyLoaded;     /*!< \brief Загружено ли тело сообщения */ 
    28         int        Special;          /*!< \brief Спец-данные */ 
    29 } AMessageInfoGUI; 
    30 //---------------------------------------------------------------------------------------------- 
    31 /*! 
    32  * \brief Элемент для дерева группы форумов с информацией о группе 
    33  */ 
    34 typedef ATreeWidgetItemT<AMessageInfoGUI> MessageTreeWidgetItem; 
    359//---------------------------------------------------------------------------------------------- 
    3610 
     
    4115        m_message_view = 0; 
    4216        m_main_form    = 0; 
    43         m_id_group     = 0; 
    44         m_id_forum     = 0; 
    45         m_me.ID        = -1; 
    4617 
    4718        setFrameShadow(QFrame::Plain); 
     
    170141void AMessageTree::resizeEvent (QResizeEvent* event) 
    171142{ 
    172         scrollTopics(); 
    173  
    174143        QTreeWidget::resizeEvent(event); 
    175144} 
     
    216185void AMessageTree::context_menu_request (const QPoint& pos) 
    217186{ 
    218         if (currentItem() != NULL) 
    219         { 
    220                 if (m_id_group != SPECIAL_ID_GROUP) 
    221                         m_menu->exec(viewport()->mapToGlobal(pos)); 
    222                 else 
    223                 { 
    224                         if (m_id_forum == SPECIAL_ID_FORUM_MESSAGE2SEND || 
    225                             m_id_forum == SPECIAL_ID_FORUM_MODERATE2SEND) 
    226                         { 
    227                                 m_menu_special_edit->setVisible(true); 
    228  
    229                                 bool rate_visible = false; 
    230  
    231                                 m_menu_special_plus_1->setVisible(rate_visible); 
    232                                 m_menu_special_1->setVisible(rate_visible); 
    233                                 m_menu_special_2->setVisible(rate_visible); 
    234                                 m_menu_special_3->setVisible(rate_visible); 
    235                                 m_menu_special_smile->setVisible(rate_visible); 
    236                                 m_menu_special_plus->setVisible(rate_visible); 
    237                                 m_menu_special_minus->setVisible(rate_visible); 
    238                         } 
    239                         else 
    240                         { 
    241                                 m_menu_special_edit->setVisible(false); 
    242  
    243                                 bool rate_visible = true; 
    244  
    245                                 m_menu_special_plus_1->setVisible(rate_visible); 
    246                                 m_menu_special_1->setVisible(rate_visible); 
    247                                 m_menu_special_2->setVisible(rate_visible); 
    248                                 m_menu_special_3->setVisible(rate_visible); 
    249                                 m_menu_special_smile->setVisible(rate_visible); 
    250                                 m_menu_special_plus->setVisible(rate_visible); 
    251                                 m_menu_special_minus->setVisible(rate_visible); 
    252                         } 
    253  
    254                         m_menu_special->exec(viewport()->mapToGlobal(pos)); 
    255                 } 
    256         } 
    257 } 
    258 //---------------------------------------------------------------------------------------------- 
    259  
    260 bool AMessageTree::checkCurrentItem (bool select_first) 
    261 { 
    262         if (currentItem() != NULL) 
    263                 return true; 
    264  
    265         if (topLevelItemCount() == 0) 
    266                 return false; 
    267  
    268         if (select_first == true) 
    269                 setCurrentItem(topLevelItem(0)); 
    270         else 
    271         { 
    272                 setCurrentItem(topLevelItem(topLevelItemCount() - 1)); 
    273  
    274                 MessageTreeWidgetItem* item = static_cast<MessageTreeWidgetItem*>(currentItem()); 
    275  
    276                 // если элемент еще не загружен, то загружаем 
    277                 if (item->pag()->IsInfoLoaded == false) 
    278                         setCurrentItem(item); 
    279  
    280                 while (true) 
    281                 { 
    282                         item->setExpanded(true); 
    283  
    284                         item = static_cast<MessageTreeWidgetItem*>(ATreeWidgetItem::lastChild(item)); 
    285  
    286                         if (item != NULL) 
    287                                 setCurrentItem(item); 
    288                         else 
    289                                 break; 
    290                 } 
    291         } 
    292  
    293         return true; 
    294187} 
    295188//---------------------------------------------------------------------------------------------- 
     
    297190void AMessageTree::changeForum (const AForumInfo* forum_info) 
    298191{ 
    299         m_id_group    = 0; 
    300         m_id_forum    = 0; 
    301         m_me.ID       = -1; 
    302         m_forum_rated = false; 
    303  
    304         if (m_main_form != NULL) 
    305                 m_main_form->setEnabledAction(aaViewSource, false); 
    306  
    307         clear(); 
    308  
    309         m_message_view->clear(); 
    310  
    311         scrollToTop(); 
    312  
    313         // если выделена группа, то просто очистка 
    314         if (forum_info == NULL) 
    315         { 
    316                 headerItem()->setText(0, QString::fromUtf8("тема")); 
    317  
    318                 QFont font = headerItem()->font(0); 
    319                 font.setBold(false); 
    320                 headerItem()->setFont(0, font); 
    321  
    322                 return; 
    323         } 
    324  
    325         // вывод наименования форума в хедер 
    326         headerItem()->setText(0, forum_info->Name); 
    327  
    328         // получение хранилища 
    329         std::auto_ptr<IAStorage> storage(AStorageFactory::getStorage()); 
    330  
    331         if (storage.get() == NULL) 
    332         { 
    333                 QMessageBox::critical(m_parent, QString::fromUtf8("Ошибка!"), QString::fromUtf8("Не выбрано хранилище данных")); 
    334                 return; 
    335         } 
    336  
    337         // получение информации о себе 
    338         QSettings settings; 
    339  
    340         m_me.Name = settings.value("rsdn/login", "").toString(); 
    341  
    342         storage->whoAmI(m_me, NULL); 
    343  
    344         // если группа форумов обыкновенная 
    345         if (forum_info->IDGroup != SPECIAL_ID_GROUP) 
    346         { 
    347                 // получение топиков 
    348                 QList<int> topic_list; 
    349  
    350                 if (storage->getForumTopicList(forum_info->ID, AGlobal::getInstance()->MaxTopicToShow, topic_list, NULL) == false) 
    351                 { 
    352                         storage->showError(m_parent); 
    353                         return; 
    354                 } 
    355  
    356                 // установка топиков 
    357                 QList<QTreeWidgetItem*> items; 
    358  
    359                 for (int i = 0; i < topic_list.count(); i++) 
    360                 { 
    361                         MessageTreeWidgetItem* item = new MessageTreeWidgetItem(); 
    362  
    363                         AMessageInfoGUI* info = item->pag(); 
    364  
    365                         info->Info.ID          = topic_list[i]; 
    366                         info->IsInfoLoaded     = false; 
    367                         info->IsChildLoaded    = false; 
    368                         info->UnreadChildCount = 0; 
    369                         info->IsBodyLoaded     = false; 
    370                         info->Special          = 0; 
    371  
    372                         items.append(item); 
    373                 } 
    374  
    375                 // сохраняем для скролла 
    376                 m_id_group    = forum_info->IDGroup; 
    377                 m_id_forum    = forum_info->ID; 
    378                 m_forum_rated = forum_info->Rated; 
    379  
    380                 // отображение 
    381                 addTopLevelItems(items); 
    382  
    383                 // загрузка видимых топиков 
    384                 scrollTopics(); 
    385         } 
    386         else 
    387         { 
    388                 m_id_group    = forum_info->IDGroup; 
    389                 m_id_forum    = forum_info->ID; 
    390                 m_forum_rated = forum_info->Rated; 
    391  
    392                 // специальная группа форумов 
    393                 if (m_id_forum == SPECIAL_ID_FORUM_MESSAGE2SEND) 
    394                         loadMessage2Send(); 
    395                 else if (m_id_forum == SPECIAL_ID_FORUM_RATING2SEND) 
    396                         loadRating2Send(); 
    397                 else if (m_id_forum == SPECIAL_ID_FORUM_MODERATE2SEND) 
    398                         loadModerate2Send(); 
    399         } 
    400192} 
    401193//---------------------------------------------------------------------------------------------- 
     
    403195void AMessageTree::vertical_scroll (int /*value*/) 
    404196{ 
    405         scrollTopics(); 
    406 } 
    407 //---------------------------------------------------------------------------------------------- 
    408  
    409 void AMessageTree::scrollTopics () 
    410 { 
    411         // пустой форум или спец-группа 
    412         if (m_id_forum == 0 || m_id_group == SPECIAL_ID_GROUP) 
    413                 return; 
    414  
    415         // верхний видимый элемент 
    416         QTreeWidgetItem* top_item = itemAt(1, 5); 
    417  
    418         if (top_item == NULL) 
    419                 return; 
    420  
    421         while (top_item->parent() != NULL) 
    422                 top_item = top_item->parent(); 
    423  
    424         int from_index = indexOfTopLevelItem(top_item); 
    425  
    426         // нижний видимый элемент 
    427         QTreeWidgetItem* bottom_item = itemAt(1, height() - 5); 
    428  
    429         int to_index = topLevelItemCount(); 
    430  
    431         if (bottom_item != NULL) 
    432         { 
    433                 while (bottom_item->parent() != NULL) 
    434                         bottom_item = bottom_item->parent(); 
    435  
    436                 to_index = indexOfTopLevelItem(bottom_item) + 1; 
    437  
    438                 if (to_index < from_index) 
    439                         to_index = from_index + 100; // ~56 элементов влезет по высоте на стандартный экран 1280x1024 
    440  
    441                 if (to_index > topLevelItemCount()) 
    442                         to_index = topLevelItemCount(); 
    443         } 
    444  
    445         // поиск еще не агруженных элементов 
    446         ATopicInfoList                list; 
    447         QList<MessageTreeWidgetItem*> items; 
    448  
    449         while (from_index < to_index) 
    450         { 
    451                 MessageTreeWidgetItem* item = static_cast<MessageTreeWidgetItem*>(topLevelItem(from_index)); 
    452  
    453                 if (item->pag()->IsInfoLoaded == false) 
    454                 { 
    455                         ATopicInfo info; 
    456  
    457                         info.ID = item->pag()->Info.ID; 
    458  
    459                         list.append(info); 
    460                         items.append(item); 
    461                 } 
    462  
    463                 from_index++; 
    464         } 
    465  
    466         // загрузка топиков, которые не загружены 
    467         if (list.count() > 0) 
    468         { 
    469                 // получение хранилища 
    470                 std::auto_ptr<IAStorage> storage(AStorageFactory::getStorage()); 
    471  
    472                 if (storage.get() == NULL) 
    473                 { 
    474                         QMessageBox::critical(m_parent, QString::fromUtf8("Ошибка!"), QString::fromUtf8("Не выбрано хранилище данных")); 
    475                         return; 
    476                 } 
    477  
    478                 if (storage->getTopicInfoList(list, m_me.ID, NULL) == false) 
    479                 { 
    480                         storage->showError(m_parent); 
    481                         return; 
    482                 } 
    483  
    484                 // заполнение вновь загруженных топиков 
    485                 for (int i = 0; i < list.count(); i++) 
    486                 { 
    487                         ATopicInfo info             = list[i]; 
    488                         MessageTreeWidgetItem* item = items[i]; 
    489  
    490                         AMessageInfoGUI* item_info  = item->pag(); 
    491  
    492                         item_info->Info             = info; 
    493                         item_info->IsInfoLoaded     = true; 
    494                         item_info->IsChildLoaded    = false; 
    495                         item_info->UnreadChildCount = 0; 
    496                         item_info->IsBodyLoaded     = false; 
    497                         item_info->Special          = 0; 
    498  
    499                         item->setText(0, info.Subject); 
    500  
    501                         if (info.IDUser == 0) 
    502                                 item->setText(1, QString::fromUtf8("Аноним")); 
    503                         else 
    504                                 item->setText(1, info.UserNick); 
    505  
    506                         item->setText(2, info.MessageDate.toString("dd.MM.yyyy hh:mm:ss")); 
    507  
    508                         if (info.IsRead == true) 
    509                         { 
    510                                 if (info.HasUnreadChild != 0) 
    511                                 { 
    512                                         if (info.HasUnreadChild == 2) 
    513                                                 item->setIcon(0, m_child_unread_my); 
    514                                         else 
    515                                                 item->setIcon(0, m_child_unread); 
    516                                 } 
    517                                 else 
    518                                         item->setIcon(0, m_message_read); 
    519                         } 
    520                         else 
    521                         { 
    522                                 if (info.HasUnreadChild == 2) 
    523                                         item->setIcon(0, m_message_unread_my); 
    524                                 else 
    525                                         item->setIcon(0, m_message_unread); 
    526                         } 
    527  
    528                         if (info.HasChild == true) 
    529                                 item->setChildIndicatorPolicy(QTreeWidgetItem::ShowIndicator); 
    530                 } 
    531         } 
    532197} 
    533198//---------------------------------------------------------------------------------------------- 
     
    535200void AMessageTree::expand_item (QTreeWidgetItem* item_expanded) 
    536201{ 
    537         if (item_expanded == NULL) 
    538                 return; 
    539  
    540         MessageTreeWidgetItem* item = static_cast<MessageTreeWidgetItem*>(item_expanded); 
    541  
    542         if (item->pag()->Info.HasChild == true && item->pag()->IsChildLoaded == false) 
    543         { 
    544                 // получение хранилища 
    545                 std::auto_ptr<IAStorage> storage(AStorageFactory::getStorage()); 
    546  
    547                 if (storage.get() == NULL) 
    548                 { 
    549                         QMessageBox::critical(m_parent, QString::fromUtf8("Ошибка!"), QString::fromUtf8("Не выбрано хранилище данных")); 
    550                         return; 
    551                 } 
    552  
    553                 // получение сообщений 
    554                 ATopicInfoList list; 
    555  
    556                 if (storage->getTopicMessageList(item->pag()->Info.ID, list, m_me.ID, NULL) == false) 
    557                 { 
    558                         storage->showError(m_parent); 
    559                         return; 
    560                 } 
    561  
    562                 // постройка дерева 
    563                 buildTree(item, &list); 
    564  
    565                 // для предотвращения повторной загрузки 
    566                 item->pag()->IsChildLoaded = true; 
    567  
    568                 // раскрытие дерева до уровня непрочитаных топиков 
    569                 if (item->pag()->UnreadChildCount != 0) 
    570                         expandUnreadChild(item); 
    571         } 
    572 } 
    573 //---------------------------------------------------------------------------------------------- 
    574  
    575 void AMessageTree::expandUnreadChild (QTreeWidgetItem* widget_item) 
    576 { 
    577         MessageTreeWidgetItem* item = static_cast<MessageTreeWidgetItem*>(widget_item); 
    578  
    579         if (item->pag()->UnreadChildCount != 0) 
    580         { 
    581                 for (int i = 0; i < item->childCount(); i++) 
    582                         if (((MessageTreeWidgetItem*)item->child(i))->pag()->UnreadChildCount != 0) 
    583                                 expandUnreadChild(item->child(i)); 
    584  
    585                 expandItem(item); 
    586         } 
    587 } 
    588 //---------------------------------------------------------------------------------------------- 
    589  
    590 void AMessageTree::buildTree (QTreeWidgetItem* parent, ATopicInfoList* list) 
    591 { 
    592  
    593         MessageTreeWidgetItem* parent_item = static_cast<MessageTreeWidgetItem*>(parent); 
    594  
    595         QList<MessageTreeWidgetItem*> to_build; 
    596  
    597         int index     = 0; 
    598         int size      = list->size(); 
    599         int id_parent = parent_item->pag()->Info.ID; 
    600  
    601         while (index < size) 
    602         { 
    603                 ATopicInfo info = list->at(index); 
    604  
    605                 if (info.IDParent == id_parent) 
    606                 { 
    607                         MessageTreeWidgetItem* item = new MessageTreeWidgetItem(parent_item); 
    608  
    609                         AMessageInfoGUI* item_info = item->pag(); 
    610  
    611                         // AMessageInfo 
    612                         item_info->Info.ID               = info.ID; 
    613                         item_info->Info.IDTopic          = info.IDTopic; 
    614                         item_info->Info.IDParent         = info.IDParent; 
    615                         item_info->Info.IDUser           = info.IDUser; 
    616                         item_info->Info.IDForum          = info.IDForum; 
    617                         item_info->Info.Subject          = info.Subject; 
    618                         item_info->Info.MessageName      = info.MessageName; 
    619                         item_info->Info.UserNick         = info.UserNick; 
    620                         item_info->Info.IDArticle        = info.IDArticle; 
    621                         item_info->Info.MessageDate      = info.MessageDate; 
    622                         item_info->Info.UpdateDate       = info.UpdateDate; 
    623                         item_info->Info.UserRole         = info.UserRole; 
    624                         item_info->Info.UserTitle        = info.UserTitle; 
    625                         item_info->Info.UserTitleColor   = info.UserTitleColor; 
    626                         item_info->Info.LastModerated    = info.LastModerated; 
    627  
    628                         // AMessageInfoEx 
    629                         item_info->Info.IsRead           = info.IsRead; 
    630  
    631                         // ATopicInfo 
    632                         item_info->Info.HasChild         = info.HasChild; 
    633                         item_info->Info.HasUnreadChild   = 0; 
    634  
    635                         // AMessageInfoGUI 
    636                         item_info->IsInfoLoaded          = true; 
    637                         item_info->IsChildLoaded         = true; 
    638                         item_info->UnreadChildCount      = 0; 
    639                         item_info->IsBodyLoaded          = false; 
    640                         item_info->Special               = 0; 
    641  
    642                         item->setText(0, info.Subject); 
    643  
    644                         if (info.IDUser != 0) 
    645                                 item->setText(1, info.UserNick); 
    646                         else 
    647                                 item->setText(1, QString::fromUtf8("Аноним ") + info.UserTitle); 
    648  
    649                         item->setText(2, info.MessageDate.toString("dd.MM.yyyy hh:mm:ss")); 
    650  
    651                         to_build.append(item); 
    652  
    653                         list->removeAt(index); 
    654  
    655                         size--; 
    656  
    657                         if (info.IsRead == true) 
    658                                 item->setIcon(0, m_message_read); 
    659                         else 
    660                         { 
    661                                 item->setIcon(0, m_message_unread); 
    662  
    663                                 MessageTreeWidgetItem* temp_item = parent_item; 
    664  
    665                                 while (temp_item != NULL) 
    666                                 { 
    667                                         AMessageInfoGUI* temp_info = temp_item->pag(); 
    668  
    669                                         if (info.HasUnreadChild == 2) 
    670                                                 temp_info->Info.HasUnreadChild = 2; 
    671  
    672                                         if (temp_info->Info.IsRead == true) 
    673                                         { 
    674                                                 if (temp_info->Info.HasUnreadChild == 2) 
    675                                                         temp_item->setIcon(0, m_child_unread_my); 
    676                                                 else 
    677                                                         temp_item->setIcon(0, m_child_unread); 
    678                                         } 
    679                                         else if (temp_info->Info.HasUnreadChild == 2) 
    680                                                 temp_item->setIcon(0, m_message_unread_my); 
    681  
    682                                         temp_info->UnreadChildCount++; 
    683  
    684                                         temp_item = (MessageTreeWidgetItem*)temp_item->parent(); 
    685                                 } 
    686                         } 
    687                 } 
    688                 else 
    689                         index++; 
    690         } 
    691  
    692         size = to_build.size(); 
    693  
    694         for (int i = 0; i < size; i++) 
    695                 buildTree(to_build.at(i), list); 
    696202} 
    697203//---------------------------------------------------------------------------------------------- 
     
    699205void AMessageTree::timer_on_timer () 
    700206{ 
    701         MessageTreeWidgetItem* item = static_cast<MessageTreeWidgetItem*>(currentItem()); 
    702  
    703         if (item != NULL) 
    704                 markItemAsRead(item, true); 
    705207} 
    706208//---------------------------------------------------------------------------------------------- 
     
    708210void AMessageTree::showSource () 
    709211{ 
    710         MessageTreeWidgetItem* item = static_cast<MessageTreeWidgetItem*>(currentItem()); 
    711  
    712         if (item == NULL) 
    713                 return; 
    714  
    715         std::auto_ptr<FormSource> form (new FormSource(m_parent, item->pag()->Info.Message)); 
    716         form->exec(); 
    717212} 
    718213//---------------------------------------------------------------------------------------------- 
     
    720215void AMessageTree::selection_changed () 
    721216{ 
    722         MessageTreeWidgetItem* item = static_cast<MessageTreeWidgetItem*>(currentItem()); 
    723  
    724         if (item == NULL) 
    725                 return; 
    726  
    727         if (m_main_form != NULL) 
    728                 m_main_form->setEnabledAction(aaViewSource, true); 
    729  
    730         // загрузка тела сообщения, если тело еще не загружено 
    731         if (item->pag()->IsBodyLoaded == false) 
    732         { 
    733                 // получение хранилища 
    734                 std::auto_ptr<IAStorage> storage(AStorageFactory::getStorage()); 
    735  
    736                 if (storage.get() == NULL) 
    737                 { 
    738                         QMessageBox::critical(m_parent, QString::fromUtf8("Ошибка!"), QString::fromUtf8("Не выбрано хранилище данных")); 
    739                         return; 
    740                 } 
    741  
    742                 // получение доп-информации о сообщении 
    743                 QString body; 
    744  
    745                 if (storage->getMessageBody(item->pag()->Info.ID, body, NULL) == false) 
    746                 { 
    747                         storage->showError(m_parent); 
    748                         return; 
    749                 } 
    750  
    751                 item->pag()->IsBodyLoaded = true; 
    752                 item->pag()->Info.Message = body; 
    753         } 
    754  
    755         AMessageInfoGUI message = item->tag(); 
    756  
    757         m_message_view->setMessage(message.Info, m_id_forum == SPECIAL_ID_FORUM_MESSAGE2SEND, m_forum_rated); 
    758  
    759         if (item->pag()->Info.IsRead == false) 
    760         { 
    761                 int interval = AGlobal::getInstance()->MarkAsReadTimer; 
    762  
    763                 if (interval > 0) 
    764                         m_timer.start(interval); 
    765                 else 
    766                         m_timer.stop(); 
    767         } 
    768         else 
    769                 m_timer.stop(); 
    770 } 
    771 //---------------------------------------------------------------------------------------------- 
    772  
    773 void AMessageTree::markItemAsRead (QTreeWidgetItem* widget_item, bool is_read) 
    774 { 
    775         MessageTreeWidgetItem* item = static_cast<MessageTreeWidgetItem*>(widget_item); 
    776  
    777         AMessageInfoGUI* info = item->pag(); 
    778  
    779         // если уже прочитан 
    780         if (info->Info.IsRead == is_read) 
    781                 return; 
    782  
    783         // пометить как прочитаное в хранилище 
    784         std::auto_ptr<IAStorage> storage(AStorageFactory::getStorage()); 
    785  
    786         if (storage.get() == NULL) 
    787         { 
    788                 QMessageBox::critical(m_parent, QString::fromUtf8("Ошибка!"), QString::fromUtf8("Не выбрано хранилище данных")); 
    789                 return; 
    790         } 
    791  
    792         if (storage->setIDsAsRead(QList<int>() << info->Info.ID, idsMessage, is_read, QDateTime(), NULL) == false) 
    793         { 
    794                 storage->showError(m_parent); 
    795                 return; 
    796         } 
    797  
    798         // пометка в дереве 
    799         info->Info.IsRead = is_read; 
    800  
    801         if (is_read == true) 
    802         { 
    803                 if (info->UnreadChildCount != 0) 
    804                 { 
    805                         if (info->Info.HasUnreadChild == 2) 
    806                                 item->setIcon(0, m_child_unread_my); 
    807                         else 
    808                                 item->setIcon(0, m_child_unread); 
    809                 } 
    810                 else 
    811                 { 
    812                         if (item->parent() == NULL && info->IsChildLoaded == false && info->Info.HasUnreadChild != 0) 
    813                         { 
    814                                 if (info->Info.HasUnreadChild == 2) 
    815                                         item->setIcon(0, m_child_unread_my); 
    816                                 else 
    817                                         item->setIcon(0, m_child_unread); 
    818                         } 
    819                         else 
    820                         { 
    821                                 item->setIcon(0, m_message_read); 
    822                                 info->Info.HasUnreadChild = 0; 
    823                         } 
    824                 } 
    825  
    826                 MessageTreeWidgetItem* parent_item = static_cast<MessageTreeWidgetItem*>(item->parent()); 
    827  
    828                 while (parent_item != NULL) 
    829                 { 
    830                         AMessageInfoGUI* parent_info = parent_item->pag(); 
    831  
    832                         parent_info->UnreadChildCount--; 
    833  
    834                         if (parent_info->Info.IsRead == true && parent_info->UnreadChildCount == 0) 
    835                         { 
    836                                 parent_info->Info.HasUnreadChild = 0; 
    837                                 parent_item->setIcon(0, m_message_read); 
    838                         } 
    839  
    840                         parent_item = static_cast<MessageTreeWidgetItem*>(parent_item->parent()); 
    841                 } 
    842  
    843                 // уменьшение количества непрочитанных в дереве форума 
    844                 m_forum_tree->changeUnreadCount(-1); 
    845         } 
    846         else 
    847         { 
    848                 if (info->Info.HasUnreadChild == 2) 
    849                         item->setIcon(0, m_message_unread_my); 
    850                 else 
    851                         item->setIcon(0, m_message_unread); 
    852  
    853                 MessageTreeWidgetItem* parent_item = static_cast<MessageTreeWidgetItem*>(item->parent()); 
    854  
    855                 while (parent_item != NULL) 
    856                 { 
    857                         AMessageInfoGUI* parent_info = parent_item->pag(); 
    858  
    859                         parent_info->UnreadChildCount++; 
    860                         parent_info->Info.HasUnreadChild = 1; // TODO: обновить в соответствии с ответами мне 
    861  
    862                         if (parent_info->Info.IsRead == true) 
    863                         { 
    864                                 if (parent_info->Info.HasUnreadChild == 2) 
    865                                         parent_item->setIcon(0, m_child_unread_my); 
    866                                 else 
    867                                         parent_item->setIcon(0, m_child_unread); 
    868                         } 
    869  
    870                         parent_item = static_cast<MessageTreeWidgetItem*>(parent_item->parent()); 
    871                 } 
    872  
    873                 // увеличение количества непрочитанных в дереве форума 
    874                 m_forum_tree->changeUnreadCount(1); 
    875         } 
    876217} 
    877218//---------------------------------------------------------------------------------------------- 
     
    879220void AMessageTree::menu_mark_message_as_read_triggered () 
    880221{ 
    881         QTreeWidgetItem* item = currentItem(); 
    882  
    883         if (item == NULL) 
    884                 return; 
    885  
    886         markItemAsRead(item, true); 
    887222} 
    888223//---------------------------------------------------------------------------------------------- 
     
    890225void AMessageTree::menu_mark_message_as_unread_triggered () 
    891226{ 
    892         QTreeWidgetItem* item = currentItem(); 
    893  
    894         if (item == NULL) 
    895                 return; 
    896  
    897         markItemAsRead(item, false); 
    898 } 
    899 //---------------------------------------------------------------------------------------------- 
    900  
    901 void AMessageTree::markThreadAsRead (QTreeWidgetItem* parent, bool is_read, int& count) 
    902 { 
    903         MessageTreeWidgetItem* item_parent = static_cast<MessageTreeWidgetItem*>(parent); 
    904  
    905         if (item_parent->pag()->Info.IsRead != is_read) 
    906                 count++; 
    907  
    908         if (is_read == true) 
    909         { 
    910                 item_parent->setIcon(0, m_message_read); 
    911  
    912                 item_parent->pag()->Info.IsRead         = is_read; 
    913                 item_parent->pag()->UnreadChildCount    = 0; 
    914                 item_parent->pag()->Info.HasUnreadChild = (is_read == true ? 1 : 0); // TODO: обновить в соответствии с ответами мне 
    915  
    916                 for (int i = 0; i < item_parent->childCount(); i++) 
    917                         markThreadAsRead(item_parent->child(i), is_read, count); 
    918         } 
    919         else 
    920         { 
    921                 item_parent->setIcon(0, m_message_unread); 
    922  
    923                 item_parent->pag()->Info.IsRead = is_read; 
    924  
    925                 MessageTreeWidgetItem* temp_parent = static_cast<MessageTreeWidgetItem*>(parent->parent()); 
    926  
    927                 while (temp_parent != NULL) 
    928                 { 
    929                         temp_parent->pag()->Info.HasUnreadChild = (is_read == true ? 1 : 0); // TODO: обновить в соответствии с ответами мне 
    930                         temp_parent->pag()->UnreadChildCount++; 
    931                         temp_parent = static_cast<MessageTreeWidgetItem*>(temp_parent->parent()); 
    932                 } 
    933  
    934                 for (int i = 0; i < item_parent->childCount(); i++) 
    935                         markThreadAsRead(item_parent->child(i), is_read, count); 
    936         } 
    937227} 
    938228//---------------------------------------------------------------------------------------------- 
     
    940230void AMessageTree::menu_mark_thread_as_read_triggered () 
    941231{ 
    942         QTreeWidgetItem* item = currentItem(); 
    943  
    944         if (item == NULL) 
    945                 return; 
    946  
    947         // поиск родителя 
    948         QTreeWidgetItem* parent = item; 
    949  
    950         while (parent->parent() != NULL) 
    951                 parent = parent->parent(); 
    952  
    953         MessageTreeWidgetItem* item_parent = static_cast<MessageTreeWidgetItem*>(parent); 
    954  
    955         AMessageInfoGUI* info = item_parent->pag(); 
    956  
    957         // обновление данных в хранилище 
    958         std::auto_ptr<IAStorage> storage(AStorageFactory::getStorage()); 
    959  
    960         if (storage.get() == NULL) 
    961         { 
    962                 QMessageBox::critical(m_parent, QString::fromUtf8("Ошибка!"), QString::fromUtf8("Не выбрано хранилище данных")); 
    963                 return; 
    964         } 
    965  
    966         if (storage->setIDsAsRead(QList<int>() << info->Info.ID, idsTopic, true, QDateTime(), NULL) == false) 
    967         { 
    968                 storage->showError(m_parent); 
    969                 return; 
    970         } 
    971  
    972         // обновление данных в дереве 
    973         if (info->IsChildLoaded == true) 
    974         { 
    975                 int count = 0; 
    976  
    977                 markThreadAsRead(parent, true, count); 
    978  
    979                 item_parent->pag()->Info.HasUnreadChild = 0; // TODO: обновить в соответствии с ответами мне 
    980  
    981                 m_forum_tree->changeUnreadCount(-count); 
    982         } 
    983         else 
    984         { 
    985                 item_parent->setIcon(0, m_message_read); 
    986  
    987                 item_parent->pag()->Info.HasUnreadChild = 0; // TODO: обновить в соответствии с ответами мне 
    988  
    989                 // поскольку дочерние элементы еще не загружены, 
    990                 // обновление количества непрочитаных в дереве форума 
    991                 m_forum_tree->reloadUnread(false); 
    992         } 
    993232} 
    994233//---------------------------------------------------------------------------------------------- 
     
    996235void AMessageTree::menu_mark_thread_as_unread_triggered () 
    997236{ 
    998         QTreeWidgetItem* item = currentItem(); 
    999  
    1000         if (item == NULL) 
    1001                 return; 
    1002  
    1003         // поиск родителя 
    1004         QTreeWidgetItem* parent = item; 
    1005  
    1006         while (parent->parent() != NULL) 
    1007                 parent = parent->parent(); 
    1008  
    1009         MessageTreeWidgetItem* item_parent = static_cast<MessageTreeWidgetItem*>(parent); 
    1010  
    1011         AMessageInfoGUI* info = item_parent->pag(); 
    1012  
    1013         // обновление данных в хранилище 
    1014         std::auto_ptr<IAStorage> storage(AStorageFactory::getStorage()); 
    1015  
    1016         if (storage.get() == NULL) 
    1017         { 
    1018                 QMessageBox::critical(m_parent, QString::fromUtf8("Ошибка!"), QString::fromUtf8("Не выбрано хранилище данных")); 
    1019                 return; 
    1020         } 
    1021  
    1022         if (storage->setIDsAsRead(QList<int>() << info->Info.ID, idsTopic, false, QDateTime(), NULL) == false) 
    1023         { 
    1024                 storage->showError(m_parent); 
    1025                 return; 
    1026         } 
    1027  
    1028         // обновление данных в дереве 
    1029         if (info->IsChildLoaded == true) 
    1030         { 
    1031                 int count = 0; 
    1032  
    1033                 markThreadAsRead(parent, false, count); 
    1034  
    1035                 item_parent->pag()->Info.HasUnreadChild = 1; // TODO: Обновить в соответствии с ответами мне 
    1036  
    1037                 m_forum_tree->changeUnreadCount(count); 
    1038         } 
    1039         else 
    1040         { 
    1041                 item_parent->setIcon(0, m_message_unread); 
    1042  
    1043                 item_parent->pag()->Info.HasUnreadChild = 1; // TODO: Обновить в соответствии с ответами мне 
    1044  
    1045                 // поскольку дочерние элементы еще не загружены, 
    1046                 // обновление количества непрочитаных в дереве форума 
    1047                 m_forum_tree->reloadUnread(false); 
    1048         } 
    1049237} 
    1050238//---------------------------------------------------------------------------------------------- 
     
    1052240void AMessageTree::menu_reply_triggered () 
    1053241{ 
    1054         MessageTreeWidgetItem* item = static_cast<MessageTreeWidgetItem*>(currentItem()); 
    1055  
    1056         if (item == NULL) 
    1057                 return; 
    1058  
    1059         FormMessage* form = new FormMessage(NULL, true, item->pag()->Info); 
    1060  
    1061         form->setForumTree(m_forum_tree); 
    1062         form->setMainForm(m_main_form); 
    1063  
    1064         form->show(); 
    1065 } 
    1066 //---------------------------------------------------------------------------------------------- 
    1067  
    1068 void AMessageTree::loadMessage2Send () 
    1069 { 
    1070         std::auto_ptr<IAStorage> storage(AStorageFactory::getStorage()); 
    1071  
    1072         if (storage.get() == NULL) 
    1073         { 
    1074                 QMessageBox::critical(m_parent, QString::fromUtf8("Ошибка!"), QString::fromUtf8("Не выбрано хранилище данных")); 
    1075                 return; 
    1076         } 
    1077  
    1078         AMessageInfoList list; 
    1079  
    1080         if (storage->getMessage2SendList(list, NULL) == false) 
    1081         { 
    1082                 storage->showError(m_parent); 
    1083                 return; 
    1084         } 
    1085  
    1086         QList<QTreeWidgetItem*> items; 
    1087  
    1088         for (int i = 0; i < list.count(); i++) 
    1089         { 
    1090                 MessageTreeWidgetItem* item = new MessageTreeWidgetItem(); 
    1091  
    1092                 AMessageInfoGUI* info = item->pag(); 
    1093  
    1094                 info->Info.ID             = list[i].ID; 
    1095                 info->Info.IDTopic        = list[i].IDTopic; 
    1096                 info->Info.IDParent       = list[i].IDParent; 
    1097                 info->Info.IDUser         = list[i].IDUser; 
    1098                 info->Info.IDForum        = list[i].IDForum; 
    1099                 info->Info.Subject        = list[i].Subject; 
    1100                 info->Info.MessageName    = list[i].MessageName; 
    1101                 info->Info.UserNick       = list[i].UserNick; 
    1102                 info->Info.Message        = list[i].Message; 
    1103                 info->Info.IDArticle      = list[i].IDArticle; 
    1104                 info->Info.MessageDate    = list[i].MessageDate; 
    1105                 info->Info.UpdateDate     = list[i].UpdateDate; 
    1106                 info->Info.UserRole       = list[i].UserRole; 
    1107                 info->Info.UserTitle      = list[i].UserTitle; 
    1108                 info->Info.UserTitleColor = list[i].UserTitleColor; 
    1109                 info->Info.LastModerated  = list[i].LastModerated; 
    1110  
    1111                 info->Info.IsRead         = true; 
    1112  
    1113                 info->Info.HasChild       = false; 
    1114                 info->Info.HasUnreadChild = 0; 
    1115  
    1116                 info->IsInfoLoaded        = true; 
    1117                 info->IsChildLoaded       = true; 
    1118                 info->UnreadChildCount    = 0; 
    1119                 info->IsBodyLoaded        = true; 
    1120                 info->Special             = list[i].ID; 
    1121  
    1122                 item->setText(0, info->Info.Subject); 
    1123  
    1124                 if (info->Info.IDUser == 0) 
    1125                 { 
    1126                         info->Info.UserNick = QString::fromUtf8("(локальный)"); 
    1127                         item->setText(1, info->Info.UserNick); 
    1128                 } 
    1129                 else 
    1130                         item->setText(1, info->Info.UserNick); 
    1131  
    1132                 item->setText(2, info->Info.MessageDate.toString("dd.MM.yyyy hh:mm:ss")); 
    1133  
    1134                 items.append(item); 
    1135         } 
    1136  
    1137         addTopLevelItems(items); 
    1138242} 
    1139243//---------------------------------------------------------------------------------------------- 
     
    1141245void AMessageTree::processUrl (const QString& url) 
    1142246{ 
    1143         MessageTreeWidgetItem* item = static_cast<MessageTreeWidgetItem*>(currentItem()); 
    1144  
    1145         if (item == NULL) 
    1146                 return; 
    1147  
    1148         int     rate; 
    1149         QString title; 
    1150         QString message; 
    1151  
    1152         // оценки, модерилки 
    1153         if (url == "avalon:rate_plus_1") 
    1154         { 
    1155                 rate    = -3; 
    1156                 title   = QString::fromUtf8("Оценка +1"); 
    1157                 message = QString::fromUtf8("Поставить оценку +1?"); 
    1158         } 
    1159         else if (url == "avalon:rate_1") 
    1160         { 
    1161                 rate    = 1; 
    1162                 title   = QString::fromUtf8("Оценка 1"); 
    1163                 message = QString::fromUtf8("Оценить сообщение как интересное?"); 
    1164         } 
    1165         else if (url == "avalon:rate_2") 
    1166         { 
    1167                 rate    = 2; 
    1168                 title   = QString::fromUtf8("Оценка 2"); 
    1169                 message = QString::fromUtf8("Сказать спасибо за сообщение?"); 
    1170         } 
    1171         else if (url == "avalon:rate_3") 
    1172         { 
    1173                 rate    = 3; 
    1174                 title   = QString::fromUtf8("Оценка 3"); 
    1175                 message = QString::fromUtf8("Оценить сообщение как супер?"); 
    1176         } 
    1177         else if (url == "avalon:rate_cross") 
    1178         { 
    1179                 rate    = -1; 
    1180                 title   = QString::fromUtf8("Удаление оценки"); 
    1181                 message = QString::fromUtf8("Вы действительно хотите удалить оценку?"); 
    1182         } 
    1183         else if (url == "avalon:rate_smile") 
    1184         { 
    1185                 rate    = -2; 
    1186                 title   = QString::fromUtf8("Оценка :)"); 
    1187                 message = QString::fromUtf8("Оценить сообщение как смешное?"); 
    1188         } 
    1189         else if (url == "avalon:rate_plus") 
    1190         { 
    1191                 rate    = -4; 
    1192                 title   = QString::fromUtf8("Оценка +"); 
    1193                 message = QString::fromUtf8("Согласиться с сообщением?"); 
    1194         } 
    1195         else if (url == "avalon:rate_minus") 
    1196         { 
    1197                 rate    = 0; 
    1198                 title   = QString::fromUtf8("Оценка -"); 
    1199                 message = QString::fromUtf8("Не согласиться с сообщением?"); 
    1200         } 
    1201         else if (url == "avalon:moderate") 
    1202         { 
    1203                 FormModerate* form = new FormModerate(m_parent, item->pag()->Info.ID); 
    1204  
    1205                 form->setForumTree(m_forum_tree); 
    1206  
    1207                 form->exec(); 
    1208  
    1209                 return; 
    1210         } 
    1211         else 
    1212                 return; 
    1213  
    1214         if (QMessageBox::question(m_parent, title, message, QMessageBox::Yes | QMessageBox::No, QMessageBox::No) == QMessageBox::No) 
    1215                 return; 
    1216  
    1217         // получение хранилища 
    1218         std::auto_ptr<IAStorage> storage(AStorageFactory::getStorage()); 
    1219  
    1220         if (storage.get() == NULL) 
    1221         { 
    1222                 QMessageBox::critical(m_parent, QString::fromUtf8("Ошибка!"), QString::fromUtf8("Не выбрано хранилище данных")); 
    1223                 return; 
    1224         } 
    1225  
    1226         // подготовка данных 
    1227         ARating2Send info; 
    1228  
    1229         info.IDMessage = item->pag()->Info.ID; 
    1230         info.Rate      = rate; 
    1231         info.Date      = QDateTime::currentDateTime(); 
    1232         info.ID        = info.Date.toTime_t(); // это локальный ID 
    1233  
    1234         // добавление рейтинга 
    1235         if (storage->addRating2Send(info, NULL) == false) 
    1236         { 
    1237                 storage->showError(m_parent); 
    1238                 return; 
    1239         } 
    1240  
    1241         // обновление в дереве форумов количества непрочитаных сообщений 
    1242         if (m_forum_tree != NULL) 
    1243                 m_forum_tree->reloadUnread(false); 
    1244247} 
    1245248//---------------------------------------------------------------------------------------------- 
     
    1247250void AMessageTree::gotoNextUnreadArticle () 
    1248251{ 
    1249         if (checkCurrentItem() == false) 
    1250                 return; 
    1251  
    1252         MessageTreeWidgetItem* item = static_cast<MessageTreeWidgetItem*>(currentItem()); 
    1253  
    1254         while (true) 
    1255         { 
    1256                 if (item->pag()->Info.IsRead == false) 
    1257                         break; 
    1258  
    1259                 if (item->pag()->Info.HasUnreadChild != 0) 
    1260                         item->setExpanded(true); 
    1261  
    1262                 MessageTreeWidgetItem* next_item = static_cast<MessageTreeWidgetItem*>(ATreeWidgetItem::nextItem(item)); 
    1263  
    1264                 if (next_item == NULL) 
    1265                         item = static_cast<MessageTreeWidgetItem*>(ATreeWidgetItem::firstSibling(ATreeWidgetItem::rootItem(item))); 
    1266                 else 
    1267                         item = next_item; 
    1268  
    1269                 if (item->pag()->IsInfoLoaded == false) 
    1270                 { 
    1271                         // 
    1272                         // было 
    1273                         // 
    1274                         // setCurrentItem(item); 
    1275                         // 
    1276                         // Однако, если элемент не загружен, то ниже, скорее всего, больше нет непрочитанных сообщений 
    1277                         // иначе, начинают сканироваться все топики до конца, что занимает много времени (т.к. приходится их все грузить) 
    1278                         // по этому, переходим на корневой элемент 
    1279                         // 
    1280  
    1281                         item = static_cast<MessageTreeWidgetItem*>(ATreeWidgetItem::firstSibling(ATreeWidgetItem::rootItem(item))); 
    1282                 } 
    1283         } 
    1284  
    1285         setCurrentItem(item); 
    1286252} 
    1287253//---------------------------------------------------------------------------------------------- 
     
    1289255void AMessageTree::gotoNextUnreadThread () 
    1290256{ 
    1291         if (currentItem() == NULL) 
    1292         { 
    1293                 if (checkCurrentItem() == false) 
    1294                         return; 
    1295  
    1296                 MessageTreeWidgetItem* item = static_cast<MessageTreeWidgetItem*>(ATreeWidgetItem::rootItem(currentItem())); 
    1297  
    1298                 if (item->pag()->Info.HasUnreadChild != 0 || item->pag()->Info.IsRead == false) 
    1299                         return; 
    1300         } 
    1301  
    1302         MessageTreeWidgetItem* item = static_cast<MessageTreeWidgetItem*>(ATreeWidgetItem::rootItem(currentItem())); 
    1303  
    1304         while (true) 
    1305         { 
    1306                 MessageTreeWidgetItem* next_item = static_cast<MessageTreeWidgetItem*>(ATreeWidgetItem::nextSibling(item)); 
    1307  
    1308                 if (next_item == NULL) 
    1309                         next_item = static_cast<MessageTreeWidgetItem*>(ATreeWidgetItem::firstSibling(item)); 
    1310  
    1311                 item = next_item; 
    1312  
    1313                 // 
    1314                 // было 
    1315                 // 
    1316                 // if (item->pag()->IsInfoLoaded == false || item->pag()->IsChildLoaded == false) 
    1317                 //      setCurrentItem(item); 
    1318                 // 
    1319                 // Однако, если элемент не загружен, то ниже, скорее всего, больше нет непрочитанных сообщений 
    1320                 // иначе, начинают сканироваться все топики до конца, что занимает много времени (т.к. приходится их все грузить) 
    1321                 // по этому, переходим на корневой топик 
    1322                 // 
    1323  
    1324                 if (item->pag()->IsInfoLoaded == false) 
    1325                         item = static_cast<MessageTreeWidgetItem*>(ATreeWidgetItem::firstSibling(ATreeWidgetItem::rootItem(item))); 
    1326  
    1327                 if (item->pag()->Info.HasUnreadChild != 0 || item->pag()->Info.IsRead == false) 
    1328                         break; 
    1329         } 
    1330  
    1331         setCurrentItem(item); 
    1332 } 
    1333 //---------------------------------------------------------------------------------------------- 
    1334  
    1335 void AMessageTree::loadRating2Send () 
    1336 { 
    1337         std::auto_ptr<IAStorage> storage(AStorageFactory::getStorage()); 
    1338  
    1339         if (storage.get() == NULL) 
    1340         { 
    1341                 QMessageBox::critical(m_parent, QString::fromUtf8("Ошибка!"), QString::fromUtf8("Не выбрано хранилище данных")); 
    1342                 return; 
    1343         } 
    1344  
    1345         AMessageInfoList message_list; 
    1346         ARating2SendList rating_list; 
    1347  
    1348         if (storage->getRating2SendList(message_list, rating_list, NULL) == false) 
    1349         { 
    1350                 storage->showError(m_parent); 
    1351                 return; 
    1352         } 
    1353  
    1354         QList<QTreeWidgetItem*> items; 
    1355  
    1356         for (int i = 0; i < message_list.count(); i++) 
    1357         { 
    1358                 MessageTreeWidgetItem* item = new MessageTreeWidgetItem(); 
    1359  
    1360                 AMessageInfoGUI* info = item->pag(); 
    1361  
    1362                 info->Info.ID             = message_list[i].ID; 
    1363                 info->Info.IDTopic        = message_list[i].IDTopic; 
    1364                 info->Info.IDParent       = message_list[i].IDParent; 
    1365                 info->Info.IDUser         = message_list[i].IDUser; 
    1366                 info->Info.IDForum        = message_list[i].IDForum; 
    1367                 info->Info.Subject        = message_list[i].Subject; 
    1368                 info->Info.MessageName    = message_list[i].MessageName; 
    1369                 info->Info.UserNick       = message_list[i].UserNick; 
    1370                 info->Info.Message        = message_list[i].Message; 
    1371                 info->Info.IDArticle      = message_list[i].IDArticle; 
    1372                 info->Info.MessageDate    = message_list[i].MessageDate; 
    1373                 info->Info.UpdateDate     = message_list[i].UpdateDate; 
    1374                 info->Info.UserRole       = message_list[i].UserRole; 
    1375                 info->Info.UserTitle      = message_list[i].UserTitle; 
    1376                 info->Info.UserTitleColor = message_list[i].UserTitleColor; 
    1377                 info->Info.LastModerated  = message_list[i].LastModerated; 
    1378  
    1379                 info->Info.IsRead         = true; 
    1380  
    1381                 info->Info.HasChild       = false; 
    1382                 info->Info.HasUnreadChild = 0; 
    1383  
    1384                 info->IsInfoLoaded        = true; 
    1385                 info->IsChildLoaded       = true; 
    1386                 info->UnreadChildCount    = 0; 
    1387                 info->IsBodyLoaded        = true; 
    1388                 info->Special             = rating_list[i].ID; 
    1389  
    1390                 item->setText(0, info->Info.Subject); 
    1391  
    1392                 if (info->Info.IDUser == 0) 
    1393                 { 
    1394                         info->Info.UserNick = QString::fromUtf8("(локальный)"); 
    1395                         item->setText(1, info->Info.UserNick); 
    1396                 } 
    1397                 else 
    1398                         item->setText(1, info->Info.UserNick); 
    1399  
    1400                 item->setText(2, info->Info.MessageDate.toString("dd.MM.yyyy hh:mm:ss")); 
    1401  
    1402                 int rate = rating_list[i].Rate; 
    1403  
    1404                 if (rate == -4) 
    1405                         item->setIcon(0, m_rating_plus); 
    1406                 else if (rate == -3) 
    1407                         item->setIcon(0, m_rating_plus_1); 
    1408                 else if (rate == -2) 
    1409                         item->setIcon(0, m_rating_smile); 
    1410                 else if (rate == -1) 
    1411                         item->setIcon(0, m_rating_cross); 
    1412                 else if (rate == 0) 
    1413                         item->setIcon(0, m_rating_minus); 
    1414                 else if (rate == 1) 
    1415                         item->setIcon(0, m_rating_1); 
    1416                 else if (rate == 2) 
    1417                         item->setIcon(0, m_rating_2); 
    1418                 else if (rate == 3) 
    1419                         item->setIcon(0, m_rating_3); 
    1420  
    1421                 items.append(item); 
    1422         } 
    1423  
    1424         addTopLevelItems(items); 
    1425 } 
    1426 //---------------------------------------------------------------------------------------------- 
    1427  
    1428 void AMessageTree::loadModerate2Send () 
    1429 { 
    1430         std::auto_ptr<IAStorage> storage(AStorageFactory::getStorage()); 
    1431  
    1432         if (storage.get() == NULL) 
    1433         { 
    1434                 QMessageBox::critical(m_parent, QString::fromUtf8("Ошибка!"), QString::fromUtf8("Не выбрано хранилище данных")); 
    1435                 return; 
    1436         } 
    1437  
    1438         AMessageInfoList message_list; 
    1439         AModerate2SendList moderate_list; 
    1440  
    1441         if (storage->getModerate2SendList(message_list, moderate_list, NULL) == false) 
    1442         { 
    1443                 storage->showError(m_parent); 
    1444                 return; 
    1445         } 
    1446  
    1447         QList<QTreeWidgetItem*> items; 
    1448  
    1449         for (int i = 0; i < message_list.count(); i++) 
    1450         { 
    1451                 MessageTreeWidgetItem* item = new MessageTreeWidgetItem(); 
    1452  
    1453                 AMessageInfoGUI* info = item->pag(); 
    1454  
    1455                 info->Info.ID             = message_list[i].ID; 
    1456                 info->Info.IDTopic        = message_list[i].IDTopic; 
    1457                 info->Info.IDParent       = message_list[i].IDParent; 
    1458                 info->Info.IDUser         = message_list[i].IDUser; 
    1459                 info->Info.IDForum        = message_list[i].IDForum; 
    1460                 info->Info.Subject        = message_list[i].Subject; 
    1461                 info->Info.MessageName    = message_list[i].MessageName; 
    1462                 info->Info.UserNick       = message_list[i].UserNick; 
    1463                 info->Info.Message        = message_list[i].Message; 
    1464                 info->Info.IDArticle      = message_list[i].IDArticle; 
    1465                 info->Info.MessageDate    = message_list[i].MessageDate; 
    1466                 info->Info.UpdateDate     = message_list[i].UpdateDate; 
    1467                 info->Info.UserRole       = message_list[i].UserRole; 
    1468                 info->Info.UserTitle      = message_list[i].UserTitle; 
    1469                 info->Info.UserTitleColor = message_list[i].UserTitleColor; 
    1470                 info->Info.LastModerated  = message_list[i].LastModerated; 
    1471  
    1472                 info->Info.IsRead         = true; 
    1473  
    1474                 info->Info.HasChild       = false; 
    1475                 info->Info.HasUnreadChild = 0; 
    1476  
    1477                 info->IsInfoLoaded        = true; 
    1478                 info->IsChildLoaded       = true; 
    1479                 info->UnreadChildCount    = 0; 
    1480                 info->IsBodyLoaded        = true; 
    1481                 info->Special             = moderate_list[i].ID; 
    1482  
    1483                 item->setText(0, info->Info.Subject); 
    1484  
    1485                 if (info->Info.IDUser == 0) 
    1486                 { 
    1487                         info->Info.UserNick = QString::fromUtf8("(локальный)"); 
    1488                         item->setText(1, info->Info.UserNick); 
    1489                 } 
    1490                 else 
    1491                         item->setText(1, info->Info.UserNick); 
    1492  
    1493                 item->setText(2, info->Info.MessageDate.toString("dd.MM.yyyy hh:mm:ss")); 
    1494  
    1495                 item->setIcon(0, m_moderate); 
    1496  
    1497                 items.append(item); 
    1498         } 
    1499  
    1500         addTopLevelItems(items); 
    1501257} 
    1502258//---------------------------------------------------------------------------------------------- 
     
    1504260void AMessageTree::menu_special_delete_triggered () 
    1505261{ 
    1506         MessageTreeWidgetItem* item = static_cast<MessageTreeWidgetItem*>(currentItem()); 
    1507  
    1508         if (item == NULL) 
    1509                 return; 
    1510  
    1511         if (!(m_id_forum == SPECIAL_ID_FORUM_MESSAGE2SEND || m_id_forum == SPECIAL_ID_FORUM_RATING2SEND || m_id_forum == SPECIAL_ID_FORUM_MODERATE2SEND)) 
    1512                 return; 
    1513  
    1514         std::auto_ptr<IAStorage> storage(AStorageFactory::getStorage()); 
    1515  
    1516         if (storage.get() == NULL) 
    1517         { 
    1518                 QMessageBox::critical(m_parent, QString::fromUtf8("Ошибка!"), QString::fromUtf8("Не выбрано хранилище данных")); 
    1519                 return; 
    1520         } 
    1521  
    1522         if (storage->deleteSpecial(QList<int>() << item->pag()->Special, m_id_forum, NULL) == false) 
    1523         { 
    1524                 storage->showError(m_parent); 
    1525                 return; 
    1526         } 
    1527  
    1528         // обновление в дереве форумов количества непрочитаных сообщений 
    1529         if (m_forum_tree != NULL) 
    1530                 m_forum_tree->reloadUnread(true); 
    1531262} 
    1532263//---------------------------------------------------------------------------------------------- 
     
    1534265void AMessageTree::item_double_clicked (QTreeWidgetItem* item, int /*column*/) 
    1535266{ 
    1536         if (item == NULL) 
    1537                 return; 
    1538  
    1539         setCurrentItem(item); 
    1540  
    1541         if (!(m_id_forum == SPECIAL_ID_FORUM_MESSAGE2SEND || m_id_forum == SPECIAL_ID_FORUM_RATING2SEND || m_id_forum == SPECIAL_ID_FORUM_MODERATE2SEND)) 
    1542                 return; 
    1543  
    1544         menu_special_edit_triggered(); 
    1545267} 
    1546268//---------------------------------------------------------------------------------------------- 
     
    1548270void AMessageTree::menu_special_edit_triggered () 
    1549271{ 
    1550         MessageTreeWidgetItem* item = static_cast<MessageTreeWidgetItem*>(currentItem()); 
    1551  
    1552         if (item == NULL) 
    1553                 return; 
    1554  
    1555         if (!(m_id_forum == SPECIAL_ID_FORUM_MESSAGE2SEND || m_id_forum == SPECIAL_ID_FORUM_RATING2SEND || m_id_forum == SPECIAL_ID_FORUM_MODERATE2SEND)) 
    1556                 return; 
    1557  
    1558         if (m_id_forum == SPECIAL_ID_FORUM_MESSAGE2SEND) 
    1559         { 
    1560                 FormMessage* form = new FormMessage(NULL, false, item->pag()->Info, item->pag()->Special); 
    1561  
    1562                 form->setForumTree(m_forum_tree); 
    1563                 form->setMainForm(m_main_form); 
    1564  
    1565                 form->show(); 
    1566         } 
    1567         else if (m_id_forum == SPECIAL_ID_FORUM_MODERATE2SEND) 
    1568         { 
    1569                 FormModerate* form = new FormModerate(m_parent, item->pag()->Info.ID, item->pag()->Special); 
    1570  
    1571                 form->setForumTree(m_forum_tree); 
    1572  
    1573                 form->exec(); 
    1574  
    1575                 return; 
    1576         } 
    1577 } 
    1578 //---------------------------------------------------------------------------------------------- 
    1579  
    1580 void AMessageTree::changeRating (int new_rate) 
    1581 { 
    1582         MessageTreeWidgetItem* item = static_cast<MessageTreeWidgetItem*>(currentItem()); 
    1583  
    1584         if (item == NULL) 
    1585                 return; 
    1586  
    1587         if (m_id_forum != SPECIAL_ID_FORUM_RATING2SEND) 
    1588                 return; 
    1589  
    1590         std::auto_ptr<IAStorage> storage(AStorageFactory::getStorage()); 
    1591  
    1592         if (storage.get() == NULL) 
    1593         { 
    1594                 QMessageBox::critical(m_parent, QString::fromUtf8("Ошибка!"), QString::fromUtf8("Не выбрано хранилище данных")); 
    1595                 return; 
    1596         } 
    1597  
    1598         if (storage->changeRating(item->pag()->Special, new_rate, NULL) == false) 
    1599         { 
    1600                 storage->showError(m_parent); 
    1601                 return; 
    1602         } 
    1603  
    1604         if (new_rate == -4) 
    1605                 item->setIcon(0, m_rating_plus); 
    1606         else if (new_rate == -3) 
    1607                 item->setIcon(0, m_rating_plus_1); 
    1608         else if (new_rate == -2) 
    1609                 item->setIcon(0, m_rating_smile); 
    1610         else if (new_rate == -1) 
    1611                 item->setIcon(0, m_rating_cross); 
    1612         else if (new_rate == 0) 
    1613                 item->setIcon(0, m_rating_minus); 
    1614         else if (new_rate == 1) 
    1615                 item->setIcon(0, m_rating_1); 
    1616         else if (new_rate == 2) 
    1617                 item->setIcon(0, m_rating_2); 
    1618         else if (new_rate == 3) 
    1619                 item->setIcon(0, m_rating_3); 
    1620272} 
    1621273//---------------------------------------------------------------------------------------------- 
     
    1623275void AMessageTree::menu_special_plus_1_triggered () 
    1624276{ 
    1625         changeRating(-3); 
    1626277} 
    1627278//---------------------------------------------------------------------------------------------- 
     
    1629280void AMessageTree::menu_special_1_triggered () 
    1630281{ 
    1631         changeRating(1); 
    1632282} 
    1633283//---------------------------------------------------------------------------------------------- 
     
    1635285void AMessageTree::menu_special_2_triggered () 
    1636286{ 
    1637         changeRating(2); 
    1638287} 
    1639288//---------------------------------------------------------------------------------------------- 
     
    1641290void AMessageTree::menu_special_3_triggered () 
    1642291{ 
    1643         changeRating(3); 
    1644292} 
    1645293//---------------------------------------------------------------------------------------------- 
     
    1647295void AMessageTree::menu_special_smile_triggered () 
    1648296{ 
    1649         changeRating(-2); 
    1650297} 
    1651298//---------------------------------------------------------------------------------------------- 
     
    1653300void AMessageTree::menu_special_plus_triggered () 
    1654301{ 
    1655         changeRating(-4); 
    1656302} 
    1657303//---------------------------------------------------------------------------------------------- 
     
    1659305void AMessageTree::menu_special_minus_triggered () 
    1660306{ 
    1661         changeRating(0); 
    1662307} 
    1663308//---------------------------------------------------------------------------------------------- 
     
    1665310void AMessageTree::getSelectedPath (QList<int>& path) 
    1666311{ 
    1667         MessageTreeWidgetItem* item = static_cast<MessageTreeWidgetItem*>(currentItem()); 
    1668  
    1669         if (item == NULL) 
    1670                 return; 
    1671  
    1672         path.insert(0, item->pag()->Info.ID); 
    1673  
    1674         while (true) 
    1675         { 
    1676                 item = static_cast<MessageTreeWidgetItem*>(item->parent()); 
    1677  
    1678                 if (item != NULL) 
    1679                         path.insert(0, item->pag()->Info.ID); 
    1680                 else 
    1681                         break; 
    1682         } 
    1683312} 
    1684313//---------------------------------------------------------------------------------------------- 
     
    1686315bool AMessageTree::selectByPath (const QList<int>* path) 
    1687316{ 
    1688         if (path == NULL || path->count() == 0) 
    1689                 return false; 
    1690  
    1691         int root_id = path->at(0); 
    1692  
    1693         MessageTreeWidgetItem* root_item = NULL; 
    1694  
    1695         // поиск в корне 
    1696         for (int i = 0; i < topLevelItemCount(); i++) 
    1697         { 
    1698                 MessageTreeWidgetItem* item = static_cast<MessageTreeWidgetItem*>(topLevelItem(i)); 
    1699  
    1700                 if (item->pag()->IsInfoLoaded == false) 
    1701                         return false; 
    1702  
    1703                 if (item->pag()->Info.ID == root_id) 
    1704                 { 
    1705                         root_item = item; 
    1706  
    1707                         // переход на корень 
    1708                         setCurrentItem(root_item); 
    1709  
    1710                         // ... и разворот, если ищется некорневое сообщение 
    1711                         if (path->count() > 1 && root_item->isExpanded() == false) 
    1712                                 root_item->setExpanded(true); 
    1713  
    1714                         break; 
    1715                 } 
    1716         } 
    1717  
    1718         // поиск в дочерних 
    1719         for (int i = 1; i < path->count(); i++) 
    1720         { 
    1721                 bool found = false; 
    1722  
    1723                 int next_id = path->at(i); 
    1724  
    1725                 for (int j = 0; j < root_item->childCount(); j++) 
    1726                 { 
    1727                         MessageTreeWidgetItem* item = static_cast<MessageTreeWidgetItem*>(root_item->child(j)); 
    1728  
    1729                         if (item->pag()->IsInfoLoaded == false) 
    1730                                 setCurrentItem(item); 
    1731  
    1732                         if (item->pag()->Info.ID == next_id) 
    1733                         { 
    1734                                 found = true; 
    1735                                 root_item = item; 
    1736  
    1737                                 setCurrentItem(root_item); 
    1738  
    1739                                 if (i + 1 != path->count() && root_item->isExpanded() == false) 
    1740                                         root_item->setExpanded(true); 
    1741  
    1742                                 break; 
    1743                         } 
    1744                 } 
    1745  
    1746                 if (found == false) 
    1747                         return false; 
    1748         } 
    1749  
    1750         return true; 
    1751 } 
    1752 //---------------------------------------------------------------------------------------------- 
     317} 
     318//---------------------------------------------------------------------------------------------- 
  • branches/message_tree/message_tree.h

    r177 r178  
    129129                QAction* m_menu_special_minus;  /*!< \brief - (несогласен) */ 
    130130 
    131                 /*! 
    132                  * \brief ID текущей группы 
    133                  */ 
    134                 int m_id_group; 
    135  
    136                 /*! 
    137                  * \brief ID текущего форума 
    138                  */ 
    139                 int m_id_forum; 
    140  
    141                 /*! 
    142                  * \brief Оценивается ли форум 
    143                  */ 
    144                 bool m_forum_rated; 
    145  
    146                 /*! 
    147                  * \brief ID текущего пользователя RSDN 
    148                  */ 
    149                 AUserInfo m_me; 
    150  
    151                 /*! 
    152                  * \brief Функция проверки установки выделения, в случае отсутствия выделения, выделяет элемент, согласно параметру select_first 
    153                  * \param select_first Флаг выделения, если имеет значение true, то выделяется первый элемент, иначе, последний (из корневых) 
    154                  * \return true, если есть выделение, false при отсутствии элементов 
    155                  */ 
    156                 bool checkCurrentItem (bool select_first = true); 
    157  
    158                 /*! 
    159                  * \brief Загружает незагруженные топики при скроллинге (см. алгоритм работы с деревом в trac) 
    160                  */ 
    161                 void scrollTopics (); 
    162  
    163                 /*! 
    164                  * \brief Разворачивает ветку до непрочитанных сообщений 
    165                  * \param item Элемент для разворачивания 
    166                  */ 
    167                 void expandUnreadChild (QTreeWidgetItem* item); 
    168  
    169                 /*! 
    170                  * \brief Построение веток 
    171                  * \param parent Родительский элемент 
    172                  * \param list список _всех_ дочерних веток (все уровни вложенности) 
    173                  */ 
    174                 void buildTree (QTreeWidgetItem* parent, ATopicInfoList* list); 
    175  
    176                 /*! 
    177                  * \brief Пометка сообщения как прочитанного 
    178                  * \param item Элемент дерева 
    179                  * \param is_read Флаг прочитанности/непрочитанности 
    180                  */ 
    181                 void markItemAsRead (QTreeWidgetItem* item, bool is_read); 
    182  
    183                 /*! 
    184                  * \brief Пометка ветки как прочитаной 
    185                  * \param parent Родительский элемент ветки 
    186                  * \param is_read Флаг прочитанности/непрочитанности 
    187                  * \param count Количество отмеченных элементов 
    188                  */ 
    189                 void markThreadAsRead (QTreeWidgetItem* parent, bool is_read, int& count); 
    190  
    191                 /*! 
    192                  * \brief Загрузить сообщения к отправке 
    193                  */ 
    194                 void loadMessage2Send (); 
    195  
    196                 /*! 
    197                  * \brief Загрузить рейтинги к отправке 
    198                  */ 
    199                 void loadRating2Send (); 
    200  
    201                 /*! 
    202                  * \brief Загрузить модерилки к отправке 
    203                  */ 
    204                 void loadModerate2Send (); 
    205  
    206                 /*! 
    207                  * \brief Смена оценки 
    208                  * \param new_rate Новая оценка 
    209                  */ 
    210                 void changeRating (int new_rate); 
    211  
    212131        // IMessageTree 
    213132        public: 
  • branches/message_tree/version.h

    r177 r178  
    2020 * \brief Дата билда (заменяется автоматически при каждом билде в version.h, что и приводит к смене номера ревизии) 
    2121 */ 
    22 #define AVALON_DATE "Пнд Мар 23 08:11:26 MSK 2009" 
     22#define AVALON_DATE "Пнд Мар 23 09:01:24 MSK 2009" 
    2323 
    2424#endif 
Note: See TracChangeset for help on using the changeset viewer.