Changeset 188


Ignore:
Timestamp:
03/27/09 14:56:44 (3 years ago)
Author:
antonbatenev.ya.ru
Message:

Бранч. Промежуточный.

Location:
branches/message_tree
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • branches/message_tree/message_tree.cpp

    r187 r188  
    453453        } 
    454454 
    455         // обновление в дереве форумов количества непрочитаных сообщений 
     455        // обновление в дереве форумов количества непрочитанных сообщений 
    456456        if (m_forum_tree != NULL) 
    457457                m_forum_tree->reloadUnread(false); 
     
    554554        } 
    555555 
    556         // обновление в дереве форумов количества непрочитаных сообщений 
     556        // обновление в дереве форумов количества непрочитанных сообщений 
    557557        if (m_forum_tree != NULL) 
    558558                m_forum_tree->reloadUnread(true); 
     
    773773//---------------------------------------------------------------------------------------------- 
    774774 
    775 void AMessageTree::gotoNextUnreadArticle () 
     775void AMessageTree::gotoNextUnreadArticle (QTreeWidgetItem* current_item) 
    776776{ 
    777777        AMessageInfoGUI* info = NULL; 
    778778 
    779         MessageTreeWidgetItem* item = static_cast<MessageTreeWidgetItem*>(currentItem()); 
     779        MessageTreeWidgetItem* item = static_cast<MessageTreeWidgetItem*>(current_item); 
    780780 
    781781        // если не было выделения, то ищем первый непрочитанный топик или топик с непрочитанными сообщениями 
     
    886886//---------------------------------------------------------------------------------------------- 
    887887 
     888void AMessageTree::gotoNextUnreadArticle () 
     889{ 
     890        gotoNextUnreadArticle(currentItem()); 
     891} 
     892//---------------------------------------------------------------------------------------------- 
     893 
    888894void AMessageTree::gotoNextUnreadThread () 
    889895{ 
     
    895901        if (item == NULL) 
    896902        { 
    897                 gotoNextUnreadArticle(); 
     903                gotoNextUnreadArticle(NULL); 
    898904                return; 
    899905        } 
    900906 
    901907        // item установлен на топик 
    902         item = ATreeWidgetItem::rootItem(item); 
     908        item = static_cast<MessageTreeWidgetItem*>(ATreeWidgetItem::rootItem(item)); 
    903909        info = item->pag(); 
    904910 
     
    906912        bool loopback = false; 
    907913 
    908         // поиск следующего топика с непрочитанными 
     914        // поиск следующего топика с непрочитанными сообщениями 
    909915        while (true) 
    910916        { 
    911917                // следующий топик за текущим 
    912                 MessageTreeWidgetItem* item = ATreeWidgetItem::nextSibling(item); 
     918                item = static_cast<MessageTreeWidgetItem*>(ATreeWidgetItem::nextSibling(item)); 
    913919 
    914920                // если достигнут конец дерева, то переходим в корень 
     
    929935                        loopback = true; 
    930936                } 
    931                 else if (info->IsRead == false) 
     937 
     938                if (info->IsRead == false) 
    932939                        break; 
    933                 else if (info->HasUnreadChild == true) 
    934                 { 
    935                         DONT COMPILE THIS!!! 
     940 
     941                if (info->HasUnreadChild == true) 
     942                { 
     943                        gotoNextUnreadArticle(item); 
     944                        return; 
    936945                } 
    937946        } 
     
    945954void AMessageTree::menu_mark_message_as_read_triggered () 
    946955{ 
     956        QTreeWidgetItem* item = currentItem(); 
     957 
     958        if (item == NULL) 
     959                return; 
     960 
     961        markItemAsRead(item, true); 
    947962} 
    948963//---------------------------------------------------------------------------------------------- 
     
    950965void AMessageTree::menu_mark_message_as_unread_triggered () 
    951966{ 
    952 } 
    953 //---------------------------------------------------------------------------------------------- 
    954  
    955 void AMessageTree::menu_mark_thread_as_read_triggered () 
    956 { 
    957 } 
    958 //---------------------------------------------------------------------------------------------- 
    959  
    960 void AMessageTree::menu_mark_thread_as_unread_triggered () 
    961 { 
     967        QTreeWidgetItem* item = currentItem(); 
     968 
     969        if (item == NULL) 
     970                return; 
     971 
     972        markItemAsRead(item, false); 
    962973} 
    963974//---------------------------------------------------------------------------------------------- 
     
    965976void AMessageTree::timer_on_timer () 
    966977{ 
     978        MessageTreeWidgetItem* item = static_cast<MessageTreeWidgetItem*>(currentItem()); 
     979 
     980        if (item != NULL) 
     981                markItemAsRead(item, true); 
     982} 
     983//---------------------------------------------------------------------------------------------- 
     984 
     985void AMessageTree::markItemAsRead (QTreeWidgetItem* widget_item, bool is_read) 
     986{ 
     987        MessageTreeWidgetItem* item = static_cast<MessageTreeWidgetItem*>(widget_item); 
     988 
     989        AMessageInfoGUI* info = item->pag(); 
     990 
     991        // если уже прочитан 
     992        if (info->IsRead == is_read) 
     993                return; 
     994 
     995        // пометить как прочитанное в хранилище 
     996        std::auto_ptr<IAStorage> storage(AStorageFactory::getStorage()); 
     997 
     998        if (storage.get() == NULL) 
     999        { 
     1000                QMessageBox::critical(m_parent, QString::fromUtf8("Ошибка!"), QString::fromUtf8("Не выбрано хранилище данных")); 
     1001                return; 
     1002        } 
     1003 
     1004        if (storage->setIDsAsRead(QList<int>() << info->ID, idsMessage, is_read, QDateTime(), NULL) == false) 
     1005        { 
     1006                storage->showError(m_parent); 
     1007                return; 
     1008        } 
     1009 
     1010        // установка флага как прочитанного и пометка в дереве 
     1011        info->IsRead = is_read; 
     1012 
     1013        if (is_read == true) 
     1014        { 
     1015                // установка иконки помечаемому сообщению 
     1016                if (info->HasUnreadChildMy) 
     1017                        item->setIcon(0, m_child_unread_my); 
     1018                else if (info->HasUnreadChild) 
     1019                        item->setIcon(0, m_child_unread); 
     1020                else 
     1021                        item->setIcon(0, m_message_read); 
     1022 
     1023                // флаг того, что это было сообщение для меня 
     1024                bool message_to_me = false; 
     1025 
     1026                // установка флагов и иконок у родительских сообщений 
     1027                MessageTreeWidgetItem* item_parent = static_cast<MessageTreeWidgetItem*>(item->parent()); 
     1028 
     1029                if (item_parent != NULL && item_parent->pag()->IDUser == m_me.ID) 
     1030                        message_to_me = true; 
     1031 
     1032                while (item_parent != NULL) 
     1033                { 
     1034                        AMessageInfoGUI* info_parent = item_parent->pag(); 
     1035 
     1036                        int old_unread_count    = info_parent->UnreadChildCount; 
     1037                        int old_unread_count_my = info_parent->UnreadChildCountMy; 
     1038 
     1039                        // уменьшение количества непрочитанных дочерних 
     1040                        // и установка соответствующих флагов 
     1041                        if (info_parent->UnreadChildCount > 0) 
     1042                                info_parent->UnreadChildCount--; 
     1043 
     1044                        if (message_to_me == true && info_parent->UnreadChildCountMy > 0) 
     1045                                info_parent->UnreadChildCountMy--; 
     1046 
     1047                        if (info_parent->UnreadChildCountMy == 0) 
     1048                                info_parent->HasUnreadChildMy = false; 
     1049 
     1050                        if (info_parent->UnreadChildCount == 0) 
     1051                                info_parent->HasUnreadChild = false; 
     1052 
     1053                        // установка иконок 
     1054                        if (info_parent->IsRead == false) 
     1055                        { 
     1056                                // родитель непрочитан 
     1057 
     1058                                // если среди дочерних прочитали дочернее мне и больше непрочитанных дочерних мне нет 
     1059                                // и должна произойти смена иконки 
     1060                                if (old_unread_count_my != 0 && info_parent->UnreadChildCountMy == 0) 
     1061                                        item_parent->setIcon(0, m_message_unread); 
     1062                        } 
     1063                        else 
     1064                        { 
     1065                                // родитель прочитан 
     1066 
     1067                                // если среди дочерних есть непрочитанные мне 
     1068                                // и должна произойти смена иконки 
     1069                                if (old_unread_count_my != info_parent->UnreadChildCountMy && info_parent->UnreadChildCountMy > 0) 
     1070                                        item_parent->setIcon(0, m_child_unread_my); 
     1071 
     1072                                // если среди дочерних есть непрочитанные 
     1073                                // и должна произойти смена иконки 
     1074                                else if (old_unread_count != info_parent->UnreadChildCount && info_parent->UnreadChildCount > 0) 
     1075                                        item_parent->setIcon(0, m_child_unread); 
     1076 
     1077                                // нет дочерних непрочитанных 
     1078                                else 
     1079                                        item_parent->setIcon(0, m_message_read); 
     1080                        } 
     1081 
     1082                        item_parent = static_cast<MessageTreeWidgetItem*>(item_parent->parent()); 
     1083                } 
     1084 
     1085                // уменьшение количества непрочитанных в дереве форума 
     1086                m_forum_tree->changeUnreadCount(-1); 
     1087        } 
     1088        else   // if (is_read == true) 
     1089        { 
     1090                // TODO: Доделать пометку родителей, если отметилось сообщение, которое является ответом мне 
     1091 
     1092                // установка иконки помечаемому сообщению 
     1093                item->setIcon(0, m_message_unread); 
     1094 
     1095                // установка флагов и иконок у родительских сообщений 
     1096                MessageTreeWidgetItem* parent_item = static_cast<MessageTreeWidgetItem*>(item->parent()); 
     1097 
     1098                while (parent_item != NULL) 
     1099                { 
     1100                        AMessageInfoGUI* parent_info = parent_item->pag(); 
     1101 
     1102                        // смена иконки при необходимости 
     1103                        if (parent_info->IsRead == true && parent_info->HasUnreadChild == false) 
     1104                                parent_item->setIcon(0, m_child_unread); 
     1105 
     1106                        parent_info->UnreadChildCount++; 
     1107                        parent_info->HasUnreadChild = true; 
     1108 
     1109                        parent_item = static_cast<MessageTreeWidgetItem*>(parent_item->parent()); 
     1110                } 
     1111 
     1112                // увеличение количества непрочитанных в дереве форума 
     1113                m_forum_tree->changeUnreadCount(1); 
     1114 
     1115        }   // if (is_read == true) ... else 
    9671116} 
    9681117//---------------------------------------------------------------------------------------------- 
     
    13961545} 
    13971546//---------------------------------------------------------------------------------------------- 
     1547 
     1548bool AMessageTree::markThreadAsRead (int id, bool is_read) 
     1549{ 
     1550        std::auto_ptr<IAStorage> storage(AStorageFactory::getStorage()); 
     1551 
     1552        if (storage.get() == NULL) 
     1553        { 
     1554                QMessageBox::critical(m_parent, QString::fromUtf8("Ошибка!"), QString::fromUtf8("Не выбрано хранилище данных")); 
     1555                return false; 
     1556        } 
     1557 
     1558        if (storage->setIDsAsRead(QList<int>() << id, idsTopic, is_read, QDateTime(), NULL) == false) 
     1559        { 
     1560                storage->showError(m_parent); 
     1561                return false; 
     1562        } 
     1563 
     1564        return true; 
     1565} 
     1566//---------------------------------------------------------------------------------------------- 
     1567 
     1568void AMessageTree::menu_mark_thread_as_read_triggered () 
     1569{ 
     1570        QTreeWidgetItem* item = currentItem(); 
     1571 
     1572        if (item == NULL) 
     1573                return; 
     1574 
     1575        // поиск родителя 
     1576        QTreeWidgetItem* parent = static_cast<QTreeWidgetItem*>(ATreeWidgetItem::rootItem(item)); 
     1577 
     1578        // пометка в хранилище 
     1579        if (markThreadAsRead(parent->pag()->ID, true) != true) 
     1580                return; 
     1581 
     1582        // пометка в дереве 
     1583        markThreadAsRead(parent, true, 
     1584} 
     1585//---------------------------------------------------------------------------------------------- 
     1586 
     1587void AMessageTree::menu_mark_thread_as_unread_triggered () 
     1588{ 
     1589} 
     1590//---------------------------------------------------------------------------------------------- 
     1591 
     1592void AMessageTree::markThreadAsRead (QTreeWidgetItem* parent, bool is_read, int& count) 
     1593{ 
     1594} 
     1595//---------------------------------------------------------------------------------------------- 
  • branches/message_tree/message_tree.h

    r185 r188  
    153153 
    154154                /*! 
    155                  * \brief Раскрытие дерева элементов до всех непрочитаных сообщений 
     155                 * \brief Раскрытие дерева элементов до всех непрочитанных сообщений 
    156156                 * \param root Родительский элемент дерева для раскрытия 
    157157                 */ 
     
    170170                 */ 
    171171                void changeRating (int new_rate); 
     172 
     173                /* 
     174                 * \brief Расширенная реализация IMessageTree::gotoNextUnreadArticle 
     175                 * \param item Элемент дерева, относительно которого требуется вести поиск 
     176                 */ 
     177                void gotoNextUnreadArticle (QTreeWidgetItem* current_item); 
     178 
     179                /* 
     180                 * \brief Пометка сообщения как прочитанного/непрочитанного 
     181                 * \param item Элемент дерева 
     182                 * \param is_read Флаг прочитанного 
     183                 */ 
     184                void markItemAsRead (QTreeWidgetItem* item, bool is_read); 
     185 
     186                /* 
     187                 * \brief Пометка ветки как прочитанной/непрочитанной 
     188                 * \param item Элемент дерева 
     189                 * \param is_read Флаг прочитанного 
     190                 * \param count Количество элементов, которые были помечены 
     191                 */ 
     192                void markThreadAsRead (QTreeWidgetItem* parent, bool is_read, int& count) 
     193 
     194                /* 
     195                 * \brief Пометка ветки как прочитанной/непрочитанной в хранилище 
     196                 * \param id ID топика 
     197                 * \param is_read Флаг прочитанного 
     198                 * \return true, если ветка в хранилище помечена 
     199                 */ 
     200                bool markThreadAsRead (int id, bool is_read); 
    172201 
    173202        // IMessageTree 
  • branches/message_tree/model/message.h

    r182 r188  
    7474        bool IsBodyLoaded;       /*!< \brief Загружено ли тело сообщения                   */ 
    7575        bool IsChildLoaded;      /*!< \brief Загружены ли дочерние сообщения               */ 
    76         int HasUnreadChild;     /*!< \brief Наличие непрочитанных дочерних                */ 
    77         int HasUnreadChildMy;   /*!< \brief Наличие непрочитанных дочерних мне            */ 
     76        bool HasUnreadChild;     /*!< \brief Наличие непрочитанных дочерних                */ 
     77        bool HasUnreadChildMy;   /*!< \brief Наличие непрочитанных дочерних мне            */ 
    7878        int  UnreadChildCount;   /*!< \brief Количество непрочитанных дочерних             */ 
    7979        int  UnreadChildCountMy; /*!< \brief Количество непрочитанных дочерних мне         */ 
  • branches/message_tree/storage/mysql_storage.cpp

    r183 r188  
    20932093                                if (id_parent_user > 1) 
    20942094                                        info->HasUnreadChildMy = true; 
    2095                                 else 
    2096                                         info->HasUnreadChild = true; 
     2095 
     2096                                info->HasUnreadChild = true; 
    20972097 
    20982098                                break; 
  • branches/message_tree/version.h

    r187 r188  
    2020 * \brief Дата билда (заменяется автоматически при каждом билде в version.h, что и приводит к смене номера ревизии) 
    2121 */ 
    22 #define AVALON_DATE "Чтв Мар 26 18:55:12 MSK 2009" 
     22#define AVALON_DATE "Птн Мар 27 01:02:25 MSK 2009" 
    2323 
    2424#endif 
Note: See TracChangeset for help on using the changeset viewer.