Ticket #1208: 20070816 - Ticket 1208.diff
File 20070816 - Ticket 1208.diff, 8.2 KB (added by , 17 years ago) |
---|
-
src/apps/mail/Mail.h
92 92 M_SIZE, 93 93 M_BEGINNER, 94 94 M_EXPERT, 95 95 96 /* file */ 96 97 M_REPLY, 97 98 M_REPLY_TO_SENDER, … … 117 118 M_STATUS, 118 119 M_OPEN_MAIL_BOX, 119 120 M_OPEN_MAIL_FOLDER, 121 120 122 /* edit */ 121 123 M_SELECT, 122 124 M_QUOTE, … … 127 129 M_SIG_MENU, 128 130 M_FIND, 129 131 M_FIND_AGAIN, 132 133 /* queries */ 134 M_EDIT_QUERIES, 135 M_EXECUTE_QUERY, 136 130 137 /* encls */ 131 138 M_ADD, 132 139 M_REMOVE, 133 140 M_OPEN, 134 141 M_COPY, 142 135 143 /* nav */ 136 144 M_NEXTMSG, 137 145 M_PREVMSG, 138 146 M_SAVE_POSITION, 147 139 148 /* Spam GUI button and menu items. Order is important. */ 140 149 M_SPAM_BUTTON, 141 150 M_TRAIN_SPAM_AND_DELETE, … … 261 270 status_t TrainMessageAs (const char *CommandWord); 262 271 263 272 private: 273 const char * _BuildQueryString(BEntry *entry); 274 264 275 BEmailMessage *fMail; 265 276 entry_ref *fRef; // Reference to currently displayed file 266 277 int32 fFieldState; -
src/apps/mail/Mail.cpp
119 119 static const char *kMailFolder = "mail"; 120 120 static const char *kMailboxFolder = "mail/mailbox"; 121 121 122 static const char *kQueriesDirectory = "mail/queries"; 123 static const char *kQuerySignature = "application/x-vnd.Be-query"; // B_QUERY_MIMETYPE 124 static const char *kAttrQueryInitialMode = "_trk/qryinitmode"; // taken from src/kits/tracker/Attributes.h 125 static const char *kAttrQueryInitialString = "_trk/qryinitstr"; 126 static const char *kAttrQueryInitialNumAttrs = "_trk/qryinitnumattrs"; 127 static const char *kAttrQueryInitialAttrs = "_trk/qryinitattrs"; 128 static const char *kAttrQueryInitialMime = "_trk/qryinitmime"; 129 static const uint32 kAttributeItemMain = 'Fatr'; // taken from src/kits/tracker/FindPanel.h 130 static const uint32 kByNameItem = 'Fbyn'; // taken from src/kits/tracker/FindPanel.h 131 static const uint32 kByAttributeItem = 'Fbya'; // taken from src/kits/tracker/FindPanel.h 132 static const uint32 kByForumlaItem = 'Fbyq'; // taken from src/kits/tracker/FindPanel.h 133 122 134 static const char *kDictDirectory = "word_dictionary"; 123 135 static const char *kIndexDirectory = "word_index"; 124 136 static const char *kWordsPath = "/boot/optional/goodies/words"; 125 137 static const char *kExact = ".exact"; 126 138 static const char *kMetaphone = ".metaphone"; 127 139 128 129 140 // Text for both the main menu and the pop-up menu. 130 141 static const char *kSpamMenuItemTextArray[] = { 131 142 "Mark as Spam and Move to Trash", // M_TRAIN_SPAM_AND_DELETE … … 1227 1238 1228 1239 // #pragma mark - 1229 1240 1241 /* 1242 // Copied from src/kits/tracker/FindPanel.cpp. 1243 uint32 1244 TMailWindow::InitialMode(const BNode *node) 1245 { 1246 if (!node || node->InitCheck() != B_OK) 1247 return kByNameItem; 1248 1249 uint32 result; 1250 if (node->ReadAttr(kAttrQueryInitialMode, B_INT32_TYPE, 0, 1251 (int32 *)&result, sizeof(int32)) <= 0) 1252 return kByNameItem; 1230 1253 1254 return result; 1255 } 1256 1257 1258 // Copied from src/kits/tracker/FindPanel.cpp. 1259 int32 1260 TMailWindow::InitialAttrCount(const BNode *node) 1261 { 1262 if (!node || node->InitCheck() != B_OK) 1263 return 1; 1264 1265 int32 result; 1266 if (node->ReadAttr(kAttrQueryInitialNumAttrs, B_INT32_TYPE, 0, 1267 &result, sizeof(int32)) <= 0) 1268 return 1; 1269 1270 return result; 1271 }*/ 1272 1273 1231 1274 TMailWindow::TMailWindow(BRect rect, const char *title, const entry_ref *ref, 1232 1275 const char *to, const BFont *font, bool resending, BMessenger *messenger) 1233 1276 : BWindow(rect, title, B_DOCUMENT_WINDOW, 0), … … 1444 1487 item->SetTarget(be_app); 1445 1488 menu_bar->AddItem(menu); 1446 1489 1490 // 1447 1491 // View Menu 1448 1492 // 1449 1493 if (!resending && fIncoming) { 1450 1494 menu = new BMenu("View"); 1451 1495 menu->AddItem(fHeader = new BMenuItem(MDR_DIALECT_CHOICE ("Show Header","H) ヘッダーを表示"), new BMessage(M_HEADER), 'H')); … … 1561 1605 menu_bar->AddItem(menu); 1562 1606 } 1563 1607 1608 // 1609 // Queries Menu 1610 // 1611 menu = new BMenu(MDR_DIALECT_CHOICE("Queries","???")); 1612 menu->AddItem(new BMenuItem(MDR_DIALECT_CHOICE("Edit Queries...","???..."), new BMessage(M_EDIT_QUERIES), 'E', B_SHIFT_KEY)); 1613 menu->AddSeparatorItem(); 1614 menu_bar->AddItem(menu); 1615 1616 BPath queryPath; 1617 // Get the user home directory 1618 if (find_directory(B_USER_DIRECTORY, &queryPath) == B_OK) { 1619 queryPath.Append(kQueriesDirectory); 1620 } 1621 1622 BDirectory queryDir(queryPath.Path()); 1623 1624 // If we find the named query, add it to the menu. 1625 BEntry entry; 1626 while (queryDir.GetNextEntry(&entry) == B_OK) { 1627 1628 char name[B_FILE_NAME_LENGTH + 1]; 1629 entry.GetName(name); 1630 1631 const char * queryString = _BuildQueryString(&entry); 1632 if (queryString == NULL) 1633 continue; 1634 1635 QueryMenu *queryMenu = new QueryMenu(name, false); 1636 queryMenu->SetTargetForItems(be_app); 1637 queryMenu->SetPredicate(queryString); 1638 menu->AddItem(queryMenu); 1639 1640 delete queryString; 1641 } 1642 1643 // 1644 // Menu Bar 1645 // 1564 1646 Lock(); 1565 1647 AddChild(menu_bar); 1566 1648 height = menu_bar->Bounds().bottom + 1; … … 1668 1750 SetTitleForMessage(); 1669 1751 } 1670 1752 1753 const char * 1754 TMailWindow::_BuildQueryString(BEntry *entry) 1755 { 1756 BNode node(entry); 1757 if (node.InitCheck() != B_OK) 1758 return NULL; 1671 1759 1760 uint32 mode; 1761 if (node.ReadAttr(kAttrQueryInitialMode, B_INT32_TYPE, 0, (int32 *)&mode, sizeof(int32)) <= 0) 1762 mode = kByNameItem; 1763 1764 BString queryString; 1765 switch(mode) { 1766 case kByForumlaItem: 1767 { 1768 BString buffer; 1769 if (node.ReadAttrString(kAttrQueryInitialString, &buffer) == B_OK) 1770 queryString << buffer; 1771 break; 1772 } 1773 1774 case kByNameItem: 1775 { 1776 BString buffer; 1777 if (node.ReadAttrString(kAttrQueryInitialString, &buffer) == B_OK) 1778 queryString << "(name==*" << buffer << "*)"; 1779 break; 1780 } 1781 1782 case kByAttributeItem: 1783 { 1784 int32 count = 1; 1785 if (node.ReadAttr(kAttrQueryInitialNumAttrs, B_INT32_TYPE, 0, (int32 *)&mode, sizeof(int32)) <= 0) 1786 count = 1; 1787 1788 attr_info info; 1789 if (node.GetAttrInfo(kAttrQueryInitialAttrs, &info) != B_OK) 1790 break; 1791 1792 if (count > 1 ) 1793 queryString << "("; 1794 1795 char *buffer = new char[info.size]; 1796 if (node.ReadAttr(kAttrQueryInitialAttrs, B_MESSAGE_TYPE, 0, buffer, (size_t)info.size) == info.size) { 1797 BMessage message; 1798 if (message.Unflatten(buffer) == B_OK) { 1799 for (int32 index = 0; /*index < count*/; index++) { 1800 1801 const char *field; 1802 const char *value; 1803 if (message.FindString("menuSelection", index, &field) != B_OK 1804 || message.FindString("attrViewText", index, &value) != B_OK) 1805 break; 1806 1807 // ignore the mime type, we'll force it to be email later 1808 if (strcmp(field, "BEOS:TYPE") != 0) 1809 { 1810 // TODO: check if subMenu contains the type of comparison we are suppose to make here 1811 queryString << "(" << field << "==\"" << value << "\")"; 1812 1813 int32 logicMenuSelectedIndex; 1814 if (message.FindInt32("logicalRelation", index, &logicMenuSelectedIndex) == B_OK) { 1815 if (logicMenuSelectedIndex == 0) 1816 queryString << "&&"; 1817 else if (logicMenuSelectedIndex == 1) 1818 queryString << "||"; 1819 } else 1820 break; 1821 } 1822 } 1823 } 1824 } 1825 1826 if (count > 1 ) 1827 queryString << ")"; 1828 1829 delete [] buffer; 1830 break; 1831 } 1832 1833 default: 1834 break; 1835 } 1836 1837 if (queryString.Length() == 0) 1838 return NULL; 1839 1840 // force it to check for email only 1841 if (queryString.FindFirst("text/x-email") < 0 ) { 1842 BString temp; 1843 temp << "(" << queryString << "&&(BEOS:TYPE==\"text/x-email\"))"; 1844 queryString = temp; 1845 } 1846 1847 char * string = (char *)malloc( queryString.Length() ); 1848 sprintf( string, "%s", queryString.String() ); 1849 1850 return string; 1851 } 1852 1853 1672 1854 void 1673 1855 TMailWindow::BuildButtonBar() 1674 1856 { … … 2589 2771 fContentView->fTextView->EnableSpellCheck(fSpelling->IsMarked()); 2590 2772 } 2591 2773 break; 2774 2775 case M_EDIT_QUERIES: 2776 { 2777 BEntry folderEntry; 2778 BPath path; 2779 // Get the user home directory 2780 if (find_directory(B_USER_DIRECTORY, &path) != B_OK) 2781 break; 2782 path.Append(kQueriesDirectory); 2783 if (folderEntry.SetTo(path.Path()) == B_OK && folderEntry.Exists()) 2784 { 2785 BMessage thePackage(B_REFS_RECEIVED); 2786 BMessenger tracker("application/x-vnd.Be-TRAK"); 2592 2787 2788 entry_ref ref; 2789 folderEntry.GetRef(&ref); 2790 thePackage.AddRef("refs", &ref); 2791 tracker.SendMessage(&thePackage); 2792 } 2793 break; 2794 } 2795 2593 2796 default: 2594 2797 BWindow::MessageReceived(msg); 2595 2798 }