1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 1709 1710 1711 1712 1713 1714 1715 1716 1717 1718 1719 1720 1721 1722 1723 1724 1725 1726 1727 1728 1729 1730 1731 1732 1733 1734 1735 1736 1737 1738 1739 1740 1741 1742 1743 1744 1745 1746 1747 1748 1749 1750 1751 1752 1753 1754 1755 1756 1757 1758 1759 1760 1761 1762 1763 1764 1765 1766 1767 1768 1769 1770 1771 1772 1773 1774 1775 1776 1777 1778 1779 1780 1781 1782 1783 1784 1785 1786 1787 1788 1789 1790 1791 1792 1793 1794 1795 1796 1797 1798 1799 1800 1801 1802
|
/*
Copyright (c) 2008 Volker Krause <vkrause@kde.org>
This library is free software; you can redistribute it and/or modify it
under the terms of the GNU Library General Public License as published by
the Free Software Foundation; either version 2 of the License, or (at your
option) any later version.
This library is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public
License for more details.
You should have received a copy of the GNU Library General Public License
along with this library; see the file COPYING.LIB. If not, write to the
Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
02110-1301, USA.
*/
#include "standardactionmanager.h"
#include "actionstatemanager_p.h"
#include "agentfilterproxymodel.h"
#include "agentinstancecreatejob.h"
#include "agentmanager.h"
#include "agenttypedialog.h"
#include "collectioncreatejob.h"
#include "collectiondeletejob.h"
#include "collectiondialog.h"
#include "collectionmodel.h"
#include "collectionutils_p.h"
#include "entitytreemodel.h"
#include "favoritecollectionsmodel.h"
#include "itemdeletejob.h"
#include "itemmodel.h"
#include "metatypes.h"
#include "pastehelper_p.h"
#include "specialcollectionattribute_p.h"
#include "collectionpropertiesdialog.h"
#include "subscriptiondialog_p.h"
#include "renamefavoritedialog.h"
#include "trashjob.h"
#include "trashrestorejob.h"
#include "entitydeletedattribute.h"
#include "recentcollectionaction_p.h"
#include <KIcon>
#include <KAction>
#include <KActionCollection>
#include <KActionMenu>
#include <KDebug>
#include <KInputDialog>
#include <KLocalizedString>
#include <KMenu>
#include <KMessageBox>
#include <KToggleAction>
#include <QtCore/QMimeData>
#include <QApplication>
#include <QClipboard>
#include <QItemSelectionModel>
#include <QPointer>
#include <QWeakPointer>
#include <boost/static_assert.hpp>
using namespace Akonadi;
//@cond PRIVATE
enum ActionType
{
NormalAction,
ActionWithAlternative, //Normal action, but with an alternative state
ActionAlternative, //Alternative state of the ActionWithAlternative
MenuAction,
ToggleAction
};
static const struct {
const char *name;
const char *label;
const char *iconLabel;
const char *icon;
int shortcut;
const char *slot;
ActionType actionType;
} standardActionData[] = {
{ "akonadi_collection_create", I18N_NOOP("&New Folder..."), I18N_NOOP("New"), "folder-new", 0, SLOT(slotCreateCollection()), NormalAction },
{ "akonadi_collection_copy", 0, 0, "edit-copy", 0, SLOT(slotCopyCollections()), NormalAction },
{ "akonadi_collection_delete", I18N_NOOP("&Delete Folder"), I18N_NOOP("Delete"), "edit-delete", 0, SLOT(slotDeleteCollection()), NormalAction },
{ "akonadi_collection_sync", I18N_NOOP("&Synchronize Folder"), I18N_NOOP("Synchronize"), "view-refresh", Qt::Key_F5, SLOT(slotSynchronizeCollection()), NormalAction },
{ "akonadi_collection_properties", I18N_NOOP("Folder &Properties"), I18N_NOOP("Properties"), "configure", 0, SLOT(slotCollectionProperties()), NormalAction },
{ "akonadi_item_copy", 0, 0, "edit-copy", 0, SLOT(slotCopyItems()), NormalAction },
{ "akonadi_paste", I18N_NOOP("&Paste"), I18N_NOOP("Paste"), "edit-paste", Qt::CTRL + Qt::Key_V, SLOT(slotPaste()), NormalAction },
{ "akonadi_item_delete", 0, 0, "edit-delete", Qt::Key_Delete, SLOT(slotDeleteItems()), NormalAction },
{ "akonadi_manage_local_subscriptions", I18N_NOOP("Manage Local &Subscriptions..."), I18N_NOOP("Manage Local Subscriptions"), "folder-bookmarks", 0, SLOT(slotLocalSubscription()), NormalAction },
{ "akonadi_collection_add_to_favorites", I18N_NOOP("Add to Favorite Folders"), I18N_NOOP("Add to Favorite"), "bookmark-new", 0, SLOT(slotAddToFavorites()), NormalAction },
{ "akonadi_collection_remove_from_favorites", I18N_NOOP("Remove from Favorite Folders"), I18N_NOOP("Remove from Favorite"), "edit-delete", 0, SLOT(slotRemoveFromFavorites()), NormalAction },
{ "akonadi_collection_rename_favorite", I18N_NOOP("Rename Favorite..."), I18N_NOOP("Rename"), "edit-rename", 0, SLOT(slotRenameFavorite()), NormalAction },
{ "akonadi_collection_copy_to_menu", I18N_NOOP("Copy Folder To..."), I18N_NOOP("Copy To"), "edit-copy", 0, SLOT(slotCopyCollectionTo(QAction*)), MenuAction },
{ "akonadi_item_copy_to_menu", I18N_NOOP("Copy Item To..."), I18N_NOOP("Copy To"), "edit-copy", 0, SLOT(slotCopyItemTo(QAction*)), MenuAction },
{ "akonadi_item_move_to_menu", I18N_NOOP("Move Item To..."), I18N_NOOP("Move To"), "go-jump", 0, SLOT(slotMoveItemTo(QAction*)), MenuAction },
{ "akonadi_collection_move_to_menu", I18N_NOOP("Move Folder To..."), I18N_NOOP("Move To"), "go-jump", 0, SLOT(slotMoveCollectionTo(QAction*)), MenuAction },
{ "akonadi_item_cut", I18N_NOOP("&Cut Item"), I18N_NOOP("Cut"), "edit-cut", Qt::CTRL + Qt::Key_X, SLOT(slotCutItems()), NormalAction },
{ "akonadi_collection_cut", I18N_NOOP("&Cut Folder"), I18N_NOOP("Cut"), "edit-cut", Qt::CTRL + Qt::Key_X, SLOT(slotCutCollections()), NormalAction },
{ "akonadi_resource_create", I18N_NOOP("Create Resource"), 0, "folder-new", 0, SLOT(slotCreateResource()), NormalAction },
{ "akonadi_resource_delete", I18N_NOOP("Delete Resource"), 0, "edit-delete", 0, SLOT(slotDeleteResource()), NormalAction },
{ "akonadi_resource_properties", I18N_NOOP("&Resource Properties"), I18N_NOOP("Properties"), "configure", 0, SLOT(slotResourceProperties()), NormalAction },
{ "akonadi_resource_synchronize", I18N_NOOP("Synchronize Resource"), I18N_NOOP("Synchronize"), "view-refresh", 0, SLOT(slotSynchronizeResource()), NormalAction },
{ "akonadi_work_offline", I18N_NOOP("Work Offline"), 0, "user-offline", 0, SLOT(slotToggleWorkOffline(bool)), ToggleAction },
{ "akonadi_collection_copy_to_dialog", I18N_NOOP("Copy Folder To..."), I18N_NOOP("Copy To"), "edit-copy", 0, SLOT(slotCopyCollectionTo()), NormalAction },
{ "akonadi_collection_move_to_dialog", I18N_NOOP("Move Folder To..."), I18N_NOOP("Move To"), "go-jump", 0, SLOT(slotMoveCollectionTo()), NormalAction },
{ "akonadi_item_copy_to_dialog", I18N_NOOP("Copy Item To..."), I18N_NOOP("Copy To"), "edit-copy", 0, SLOT(slotCopyItemTo()), NormalAction },
{ "akonadi_item_move_to_dialog", I18N_NOOP("Move Item To..."), I18N_NOOP("Move To"), "go-jump", 0, SLOT(slotMoveItemTo()), NormalAction },
{ "akonadi_collection_sync_recursive", I18N_NOOP("&Synchronize Folder Recursively"), I18N_NOOP("Synchronize Recursively"), "view-refresh", Qt::CTRL + Qt::Key_F5, SLOT(slotSynchronizeCollectionRecursive()), NormalAction },
{ "akonadi_move_collection_to_trash", I18N_NOOP("&Move Folder To Trash"), I18N_NOOP("Move Folder To Trash"), "user-trash", 0, SLOT(slotMoveCollectionToTrash()), NormalAction },
{ "akonadi_move_item_to_trash", I18N_NOOP("&Move Item To Trash"), I18N_NOOP("Move Item To Trash"), "user-trash", 0, SLOT(slotMoveItemToTrash()), NormalAction },
{ "akonadi_restore_collection_from_trash", I18N_NOOP("&Restore Folder From Trash"), I18N_NOOP("Restore Folder From Trash"), "view-refresh", 0, SLOT(slotRestoreCollectionFromTrash()), NormalAction },
{ "akonadi_restore_item_from_trash", I18N_NOOP("&Restore Item From Trash"), I18N_NOOP("Restore Item From Trash"), "view-refresh", 0, SLOT(slotRestoreItemFromTrash()), NormalAction },
{ "akonadi_collection_trash_restore", I18N_NOOP("&Restore Folder From Trash"), I18N_NOOP("Restore Folder From Trash"), "user-trash", 0, SLOT(slotTrashRestoreCollection()), ActionWithAlternative },
{ 0, I18N_NOOP("&Restore Collection From Trash"), I18N_NOOP("Restore Collection From Trash"), "view-refresh", 0, 0, ActionAlternative },
{ "akonadi_item_trash_restore", I18N_NOOP("&Restore Item From Trash"), I18N_NOOP("Restore Item From Trash"), "user-trash", 0, SLOT(slotTrashRestoreItem()), ActionWithAlternative },
{ 0, I18N_NOOP("&Restore Item From Trash"), I18N_NOOP("Restore Item From Trash"), "view-refresh", 0, 0, ActionAlternative },
{ "akonadi_collection_sync_favorite_folders", I18N_NOOP("&Synchronize Favorite Folders"), I18N_NOOP("Synchronize Favorite Folders"), "view-refresh", Qt::CTRL + Qt::SHIFT + Qt::Key_L , SLOT(slotSynchronizeFavoriteCollections()), NormalAction }
};
static const int numStandardActionData = sizeof standardActionData / sizeof * standardActionData;
BOOST_STATIC_ASSERT(numStandardActionData == StandardActionManager::LastType);
static bool canCreateCollection(const Akonadi::Collection &collection)
{
if (!(collection.rights() & Akonadi::Collection::CanCreateCollection)) {
return false;
}
if (!collection.contentMimeTypes().contains(Akonadi::Collection::mimeType()) &&
!collection.contentMimeTypes().contains(Akonadi::Collection::virtualMimeType())) {
return false;
}
return true;
}
/*
static inline bool isRootCollection( const Akonadi::Collection &collection )
{
return (collection == Akonadi::Collection::root());
}
*/
static void setWorkOffline(bool offline)
{
KConfig config(QLatin1String("akonadikderc"));
KConfigGroup group(&config, QLatin1String("Actions"));
group.writeEntry("WorkOffline", offline);
}
static bool workOffline()
{
KConfig config(QLatin1String("akonadikderc"));
const KConfigGroup group(&config, QLatin1String("Actions"));
return group.readEntry("WorkOffline", false);
}
static QModelIndexList safeSelectedRows(QItemSelectionModel *selectionModel)
{
QModelIndexList selectedRows = selectionModel->selectedRows();
if (!selectedRows.isEmpty()) {
return selectedRows;
}
// try harder for selected rows that don't span the full row for some reason (e.g. due to buggy column adding proxy models etc)
foreach (const QItemSelectionRange &range, selectionModel->selection()) {
if (!range.isValid() || range.isEmpty()) {
continue;
}
const QModelIndex parent = range.parent();
for (int row = range.top(); row <= range.bottom(); ++row) {
const QModelIndex index = range.model()->index(row, range.left(), parent);
const Qt::ItemFlags flags = range.model()->flags(index);
if ((flags &Qt::ItemIsSelectable) && (flags &Qt::ItemIsEnabled)) {
selectedRows.push_back(index);
}
}
}
return selectedRows;
}
/**
* @internal
*/
class StandardActionManager::Private
{
public:
Private(StandardActionManager *parent)
: q(parent)
, actionCollection(0)
, parentWidget(0)
, collectionSelectionModel(0)
, itemSelectionModel(0)
, favoritesModel(0)
, favoriteSelectionModel(0)
, insideSelectionSlot(false)
{
actions.fill(0, StandardActionManager::LastType);
pluralLabels.insert(StandardActionManager::CopyCollections,
ki18np("&Copy Folder", "&Copy %1 Folders"));
pluralLabels.insert(StandardActionManager::CopyItems,
ki18np("&Copy Item", "&Copy %1 Items"));
pluralLabels.insert(StandardActionManager::CutItems,
ki18np("&Cut Item", "&Cut %1 Items"));
pluralLabels.insert(StandardActionManager::CutCollections,
ki18np("&Cut Folder", "&Cut %1 Folders"));
pluralLabels.insert(StandardActionManager::DeleteItems,
ki18np("&Delete Item", "&Delete %1 Items"));
pluralLabels.insert(StandardActionManager::DeleteCollections,
ki18np("&Delete Folder", "&Delete %1 Folders"));
pluralLabels.insert(StandardActionManager::SynchronizeCollections,
ki18np("&Synchronize Folder", "&Synchronize %1 Folders"));
pluralLabels.insert(StandardActionManager::DeleteResources,
ki18np("&Delete Resource", "&Delete %1 Resources"));
pluralLabels.insert(StandardActionManager::SynchronizeResources,
ki18np("&Synchronize Resource", "&Synchronize %1 Resources"));
pluralIconLabels.insert(StandardActionManager::CopyCollections,
ki18np("Copy Folder", "Copy %1 Folders"));
pluralIconLabels.insert(StandardActionManager::CopyItems,
ki18np("Copy Item", "Copy %1 Items"));
pluralIconLabels.insert(StandardActionManager::CutItems,
ki18np("Cut Item", "Cut %1 Items"));
pluralIconLabels.insert(StandardActionManager::CutCollections,
ki18np("Cut Folder", "Cut %1 Folders"));
pluralIconLabels.insert(StandardActionManager::DeleteItems,
ki18np("Delete Item", "Delete %1 Items"));
pluralIconLabels.insert(StandardActionManager::DeleteCollections,
ki18np("Delete Folder", "Delete %1 Folders"));
pluralIconLabels.insert(StandardActionManager::SynchronizeCollections,
ki18np("Synchronize Folder", "Synchronize %1 Folders"));
pluralIconLabels.insert(StandardActionManager::DeleteResources,
ki18np("Delete Resource", "Delete %1 Resources"));
pluralIconLabels.insert(StandardActionManager::SynchronizeResources,
ki18np("Synchronize Resource", "Synchronize %1 Resources"));
setContextText(StandardActionManager::CreateCollection, StandardActionManager::DialogTitle,
i18nc("@title:window", "New Folder"));
setContextText(StandardActionManager::CreateCollection, StandardActionManager::DialogText,
i18nc("@label:textbox name of a thing", "Name"));
setContextText(StandardActionManager::CreateCollection, StandardActionManager::ErrorMessageText,
ki18n("Could not create folder: %1"));
setContextText(StandardActionManager::CreateCollection, StandardActionManager::ErrorMessageTitle,
i18n("Folder creation failed"));
setContextText(StandardActionManager::DeleteCollections, StandardActionManager::MessageBoxText,
ki18np("Do you really want to delete this folder and all its sub-folders?",
"Do you really want to delete %1 folders and all their sub-folders?"));
setContextText(StandardActionManager::DeleteCollections, StandardActionManager::MessageBoxTitle,
ki18ncp("@title:window", "Delete folder?", "Delete folders?"));
setContextText(StandardActionManager::DeleteCollections, StandardActionManager::ErrorMessageText,
ki18n("Could not delete folder: %1"));
setContextText(StandardActionManager::DeleteCollections, StandardActionManager::ErrorMessageTitle,
i18n("Folder deletion failed"));
setContextText(StandardActionManager::CollectionProperties, StandardActionManager::DialogTitle,
ki18nc("@title:window", "Properties of Folder %1"));
setContextText(StandardActionManager::DeleteItems, StandardActionManager::MessageBoxText,
ki18np("Do you really want to delete the selected item?",
"Do you really want to delete %1 items?"));
setContextText(StandardActionManager::DeleteItems, StandardActionManager::MessageBoxTitle,
ki18ncp("@title:window", "Delete item?", "Delete items?"));
setContextText(StandardActionManager::DeleteItems, StandardActionManager::ErrorMessageText,
ki18n("Could not delete item: %1"));
setContextText(StandardActionManager::DeleteItems, StandardActionManager::ErrorMessageTitle,
i18n("Item deletion failed"));
setContextText(StandardActionManager::RenameFavoriteCollection, StandardActionManager::DialogTitle,
i18nc("@title:window", "Rename Favorite"));
setContextText(StandardActionManager::RenameFavoriteCollection, StandardActionManager::DialogText,
i18nc("@label:textbox name of the folder", "Name:"));
setContextText(StandardActionManager::CreateResource, StandardActionManager::DialogTitle,
i18nc("@title:window", "New Resource"));
setContextText(StandardActionManager::CreateResource, StandardActionManager::ErrorMessageText,
ki18n("Could not create resource: %1"));
setContextText(StandardActionManager::CreateResource, StandardActionManager::ErrorMessageTitle,
i18n("Resource creation failed"));
setContextText(StandardActionManager::DeleteResources, StandardActionManager::MessageBoxText,
ki18np("Do you really want to delete this resource?",
"Do you really want to delete %1 resources?"));
setContextText(StandardActionManager::DeleteResources, StandardActionManager::MessageBoxTitle,
ki18ncp("@title:window", "Delete Resource?", "Delete Resources?"));
setContextText(StandardActionManager::Paste, StandardActionManager::ErrorMessageText,
ki18n("Could not paste data: %1"));
setContextText(StandardActionManager::Paste, StandardActionManager::ErrorMessageTitle,
i18n("Paste failed"));
qRegisterMetaType<Akonadi::Item::List>("Akonadi::Item::List");
}
void enableAction(int type, bool enable)
{
enableAction(static_cast<StandardActionManager::Type>(type), enable);
}
void enableAction(StandardActionManager::Type type, bool enable)
{
Q_ASSERT(type < StandardActionManager::LastType);
if (actions[type]) {
actions[type]->setEnabled(enable);
}
// Update the action menu
KActionMenu *actionMenu = qobject_cast<KActionMenu *>(actions[type]);
if (actionMenu) {
//get rid of the submenus, they are re-created in enableAction. clear() is not enough, doesn't remove the submenu object instances.
KMenu *menu = actionMenu->menu();
//Not necessary to delete and recreate menu when it was not created
if (menu->property("actionType").isValid() && menu->isEmpty()) {
return;
}
mRecentCollectionsMenu.remove(type);
delete menu;
menu = new KMenu();
menu->setProperty("actionType", static_cast<int>(type));
q->connect(menu, SIGNAL(aboutToShow()), SLOT(aboutToShowMenu()));
q->connect(menu, SIGNAL(triggered(QAction*)), standardActionData[type].slot);
actionMenu->setMenu(menu);
}
}
void aboutToShowMenu()
{
QMenu *menu = qobject_cast<QMenu *>(q->sender());
if (!menu) {
return;
}
if (!menu->isEmpty()) {
return;
}
// collect all selected collections
const Akonadi::Collection::List selectedCollectionsList = selectedCollections();
const StandardActionManager::Type type = static_cast<StandardActionManager::Type>(menu->property("actionType").toInt());
QWeakPointer<RecentCollectionAction> recentCollection = new RecentCollectionAction(type, selectedCollectionsList, collectionSelectionModel->model(), menu);
mRecentCollectionsMenu.insert(type, recentCollection);
const QSet<QString> mimeTypes = mimeTypesOfSelection(type);
fillFoldersMenu(selectedCollectionsList,
mimeTypes,
type,
menu,
collectionSelectionModel->model(),
QModelIndex());
}
void createActionFolderMenu(QMenu *menu, StandardActionManager::Type type)
{
if (type == CopyCollectionToMenu ||
type == CopyItemToMenu ||
type == MoveItemToMenu ||
type == MoveCollectionToMenu)
{
new RecentCollectionAction(type, Akonadi::Collection::List(), collectionSelectionModel->model(), menu);
Collection::List selectedCollectionsList = selectedCollections();
const QSet<QString> mimeTypes = mimeTypesOfSelection(type);
fillFoldersMenu(selectedCollectionsList,
mimeTypes,
type,
menu,
collectionSelectionModel->model(),
QModelIndex());
}
}
void updateAlternatingAction(int type)
{
updateAlternatingAction(static_cast<StandardActionManager::Type>(type));
}
void updateAlternatingAction(StandardActionManager::Type type)
{
Q_ASSERT(type < StandardActionManager::LastType);
if (!actions[type]) {
return;
}
/*
* The same action is stored at the ActionWithAlternative indexes as well as the corresponding ActionAlternative indexes in the actions array.
* The following simply changes the standardActionData
*/
if ((standardActionData[type].actionType == ActionWithAlternative) || (standardActionData[type].actionType == ActionAlternative)) {
actions[type]->setText(i18n(standardActionData[type].label));
actions[type]->setIcon(KIcon(QString::fromLatin1(standardActionData[type].icon)));
if (pluralLabels.contains(type) && !pluralLabels.value(type).isEmpty()) {
actions[type]->setText(pluralLabels.value(type).subs(1).toString());
} else if (standardActionData[type].label) {
actions[type]->setText(i18n(standardActionData[type].label));
}
if (pluralIconLabels.contains(type) && !pluralIconLabels.value(type).isEmpty()) {
actions[type]->setIconText(pluralIconLabels.value(type).subs(1).toString());
} else if (standardActionData[type].iconLabel) {
actions[type]->setIconText(i18n(standardActionData[type].iconLabel));
}
if (standardActionData[type].icon) {
actions[type]->setIcon(KIcon(QString::fromLatin1(standardActionData[type].icon)));
}
//actions[type]->setShortcut( standardActionData[type].shortcut );
/*if ( standardActionData[type].slot ) {
switch ( standardActionData[type].actionType ) {
case NormalAction:
case ActionWithAlternative:
connect( action, SIGNAL(triggered()), standardActionData[type].slot );
break;
}
}*/
}
}
void updatePluralLabel(int type, int count)
{
updatePluralLabel(static_cast<StandardActionManager::Type>(type), count);
}
void updatePluralLabel(StandardActionManager::Type type, int count)
{
Q_ASSERT(type < StandardActionManager::LastType);
if (actions[type] && pluralLabels.contains(type) && !pluralLabels.value(type).isEmpty()) {
actions[type]->setText(pluralLabels.value(type).subs(qMax(count, 1)).toString());
}
}
bool isFavoriteCollection(const Akonadi::Collection &collection)
{
if (!favoritesModel) {
return false;
}
return favoritesModel->collectionIds().contains(collection.id());
}
void encodeToClipboard(QItemSelectionModel *selectionModel, bool cut = false)
{
Q_ASSERT(selectionModel);
if (safeSelectedRows(selectionModel).count() <= 0) {
return;
}
#ifndef QT_NO_CLIPBOARD
QAbstractItemModel *model = const_cast<QAbstractItemModel *>(selectionModel->model());
QMimeData *mimeData = selectionModel->model()->mimeData(safeSelectedRows(selectionModel));
model->setData(QModelIndex(), false, EntityTreeModel::PendingCutRole);
markCutAction(mimeData, cut);
QApplication::clipboard()->setMimeData(mimeData);
foreach (const QModelIndex &index, safeSelectedRows(selectionModel)) {
model->setData(index, true, EntityTreeModel::PendingCutRole);
}
#endif
}
void updateActions()
{
// collect all selected collections
Collection::List selectedCollectionsList;
if (collectionSelectionModel) {
const QModelIndexList rows = safeSelectedRows(collectionSelectionModel);
foreach (const QModelIndex &index, rows) {
Collection collection = index.data(EntityTreeModel::CollectionRole).value<Collection>();
if (!collection.isValid()) {
continue;
}
const Collection parentCollection = index.data(EntityTreeModel::ParentCollectionRole).value<Collection>();
collection.setParentCollection(parentCollection);
selectedCollectionsList << collection;
}
}
// collect all selected items
Item::List selectedItems;
if (itemSelectionModel) {
const QModelIndexList rows = safeSelectedRows(itemSelectionModel);
foreach (const QModelIndex &index, rows) {
Item item = index.data(EntityTreeModel::ItemRole).value<Item>();
if (!item.isValid()) {
continue;
}
const Collection parentCollection = index.data(EntityTreeModel::ParentCollectionRole).value<Collection>();
item.setParentCollection(parentCollection);
selectedItems << item;
}
}
mActionStateManager.updateState(selectedCollectionsList, selectedItems);
if (favoritesModel) {
enableAction(StandardActionManager::SynchronizeFavoriteCollections, (favoritesModel->rowCount() > 0));
}
emit q->actionStateUpdated();
}
#ifndef QT_NO_CLIPBOARD
void clipboardChanged(QClipboard::Mode mode)
{
if (mode == QClipboard::Clipboard) {
updateActions();
}
}
#endif
QItemSelection mapToEntityTreeModel(const QAbstractItemModel *model, const QItemSelection &selection) const
{
const QAbstractProxyModel *proxy = qobject_cast<const QAbstractProxyModel *>(model);
if (proxy) {
return mapToEntityTreeModel(proxy->sourceModel(), proxy->mapSelectionToSource(selection));
} else {
return selection;
}
}
QItemSelection mapFromEntityTreeModel(const QAbstractItemModel *model, const QItemSelection &selection) const
{
const QAbstractProxyModel *proxy = qobject_cast<const QAbstractProxyModel *>(model);
if (proxy) {
const QItemSelection select = mapFromEntityTreeModel(proxy->sourceModel(), selection);
return proxy->mapSelectionFromSource(select);
} else {
return selection;
}
}
// RAII class for setting insideSelectionSlot to true on entering, and false on exiting, the two slots below.
class InsideSelectionSlotBlocker {
public:
InsideSelectionSlotBlocker(Private *p)
: _p(p)
{
Q_ASSERT(!p->insideSelectionSlot);
p->insideSelectionSlot = true;
}
~InsideSelectionSlotBlocker()
{
Q_ASSERT(_p->insideSelectionSlot);
_p->insideSelectionSlot = false;
}
private:
Private *_p;
};
void collectionSelectionChanged()
{
if (insideSelectionSlot) {
return;
}
InsideSelectionSlotBlocker block(this);
QItemSelection selection = collectionSelectionModel->selection();
selection = mapToEntityTreeModel(collectionSelectionModel->model(), selection);
selection = mapFromEntityTreeModel(favoritesModel, selection);
if (favoriteSelectionModel) {
favoriteSelectionModel->select(selection, QItemSelectionModel::ClearAndSelect);
}
updateActions();
}
void favoriteSelectionChanged()
{
if (insideSelectionSlot) {
return;
}
QItemSelection selection = favoriteSelectionModel->selection();
if (selection.isEmpty()) {
return;
}
selection = mapToEntityTreeModel(favoritesModel, selection);
selection = mapFromEntityTreeModel(collectionSelectionModel->model(), selection);
InsideSelectionSlotBlocker block(this);
collectionSelectionModel->select(selection, QItemSelectionModel::ClearAndSelect | QItemSelectionModel::Rows);
// Also set the current index. This will trigger KMMainWidget::slotFolderChanged in kmail, which we want.
collectionSelectionModel->setCurrentIndex(selection.indexes().first(), QItemSelectionModel::NoUpdate);
updateActions();
}
void slotCreateCollection()
{
Q_ASSERT(collectionSelectionModel);
if (collectionSelectionModel->selection().indexes().isEmpty()) {
return;
}
const QModelIndex index = collectionSelectionModel->selection().indexes().at(0);
Q_ASSERT(index.isValid());
const Collection parentCollection = index.data(CollectionModel::CollectionRole).value<Collection>();
Q_ASSERT(parentCollection.isValid());
if (!canCreateCollection(parentCollection)) {
return;
}
QString name = KInputDialog::getText(contextText(StandardActionManager::CreateCollection, StandardActionManager::DialogTitle),
contextText(StandardActionManager::CreateCollection, StandardActionManager::DialogText),
QString(), 0, parentWidget);
name = name.trimmed();
if (name.isEmpty()) {
return;
}
if (name.contains(QLatin1Char('/'))) {
KMessageBox::error(parentWidget,
i18n("We can not add \"/\" in folder name."),
i18n("Create new folder error"));
return;
}
if (name.startsWith(QLatin1Char('.')) ||
name.endsWith(QLatin1Char('.'))) {
KMessageBox::error(parentWidget,
i18n("We can not add \".\" at begin or end of folder name."),
i18n("Create new folder error"));
return;
}
Collection collection;
collection.setName(name);
collection.setParentCollection(parentCollection);
if (actions[StandardActionManager::CreateCollection]) {
const QStringList mts = actions[StandardActionManager::CreateCollection]->property("ContentMimeTypes").toStringList();
if (!mts.isEmpty()) {
collection.setContentMimeTypes(mts);
}
}
if (parentCollection.contentMimeTypes().contains(Collection::virtualMimeType())) {
collection.setVirtual(true);
collection.setContentMimeTypes(collection.contentMimeTypes()
<< Collection::virtualMimeType());
}
CollectionCreateJob *job = new CollectionCreateJob(collection);
q->connect(job, SIGNAL(result(KJob*)), q, SLOT(collectionCreationResult(KJob*)));
}
void slotCopyCollections()
{
encodeToClipboard(collectionSelectionModel);
}
void slotCutCollections()
{
encodeToClipboard(collectionSelectionModel, true);
}
Collection::List selectedCollections()
{
Collection::List collections;
Q_ASSERT(collectionSelectionModel);
foreach (const QModelIndex &index, safeSelectedRows(collectionSelectionModel)) {
Q_ASSERT(index.isValid());
const Collection collection = index.data(CollectionModel::CollectionRole).value<Collection>();
Q_ASSERT(collection.isValid());
collections << collection;
}
return collections;
}
void slotDeleteCollection()
{
const Collection::List collections = selectedCollections();
if (collections.isEmpty()) {
return;
}
const QString collectionName = collections.first().name();
const QString text = contextText(StandardActionManager::DeleteCollections, StandardActionManager::MessageBoxText,
collections.count(), collectionName);
if (KMessageBox::questionYesNo(parentWidget, text,
contextText(StandardActionManager::DeleteCollections, StandardActionManager::MessageBoxTitle, collections.count(), collectionName),
KStandardGuiItem::del(), KStandardGuiItem::cancel(),
QString(), KMessageBox::Dangerous) != KMessageBox::Yes) {
return;
}
foreach (const Collection &collection, collections) {
CollectionDeleteJob *job = new CollectionDeleteJob(collection, q);
q->connect(job, SIGNAL(result(KJob*)), q, SLOT(collectionDeletionResult(KJob*)));
}
}
void slotMoveCollectionToTrash()
{
const Collection::List collections = selectedCollections();
if (collections.isEmpty()) {
return;
}
foreach (const Collection &collection, collections) {
TrashJob *job = new TrashJob(collection, q);
q->connect(job, SIGNAL(result(KJob*)), q, SLOT(moveCollectionToTrashResult(KJob*)));
}
}
void slotRestoreCollectionFromTrash()
{
const Collection::List collections = selectedCollections();
if (collections.isEmpty()) {
return;
}
foreach (const Collection &collection, collections) {
TrashRestoreJob *job = new TrashRestoreJob(collection, q);
q->connect(job, SIGNAL(result(KJob*)), q, SLOT(moveCollectionToTrashResult(KJob*)));
}
}
Item::List selectedItems() const
{
Item::List items;
Q_ASSERT(itemSelectionModel);
foreach (const QModelIndex &index, safeSelectedRows(itemSelectionModel)) {
Q_ASSERT(index.isValid());
const Item item = index.data(ItemModel::ItemRole).value<Item>();
Q_ASSERT(item.isValid());
items << item;
}
return items;
}
void slotMoveItemToTrash()
{
const Item::List items = selectedItems();
if (items.isEmpty()) {
return;
}
TrashJob *job = new TrashJob(items, q);
q->connect(job, SIGNAL(result(KJob*)), q, SLOT(moveItemToTrashResult(KJob*)));
}
void slotRestoreItemFromTrash()
{
const Item::List items = selectedItems();
if (items.isEmpty()) {
return;
}
TrashRestoreJob *job = new TrashRestoreJob(items, q);
q->connect(job, SIGNAL(result(KJob*)), q, SLOT(moveItemToTrashResult(KJob*)));
}
void slotTrashRestoreCollection()
{
const Collection::List collections = selectedCollections();
if (collections.isEmpty()) {
return;
}
bool collectionsAreInTrash = false;
foreach (const Collection &collection, collections) {
if (collection.hasAttribute<EntityDeletedAttribute>()) {
collectionsAreInTrash = true;
break;
}
}
if (collectionsAreInTrash) {
slotRestoreCollectionFromTrash();
} else {
slotMoveCollectionToTrash();
}
}
void slotTrashRestoreItem()
{
const Item::List items = selectedItems();
if (items.isEmpty()) {
return;
}
bool itemsAreInTrash = false;
foreach (const Item &item, items) {
if (item.hasAttribute<EntityDeletedAttribute>()) {
itemsAreInTrash = true;
break;
}
}
if (itemsAreInTrash) {
slotRestoreItemFromTrash();
} else {
slotMoveItemToTrash();
}
}
void slotSynchronizeCollection()
{
Q_ASSERT(collectionSelectionModel);
const QModelIndexList list = safeSelectedRows(collectionSelectionModel);
if (list.isEmpty()) {
return;
}
const Collection::List collections = selectedCollections();
if (collections.isEmpty()) {
return;
}
foreach (const Collection &collection, collections) {
if (!testAndSetOnlineResources(collection)) {
break;
}
AgentManager::self()->synchronizeCollection(collection, false);
}
}
bool testAndSetOnlineResources(const Akonadi::Collection &collection)
{
// Shortcut for the Search resource, which is a virtual resource and thus
// is awlays online (but AgentManager does not know about it, so it returns
// an invalid AgentInstance, which is "offline").
//
// FIXME: AgentManager should return a valid AgentInstance even
// for virtual resources, which would be always online.
if (collection.resource() == QLatin1String("akonadi_search_resource")) {
return true;
}
Akonadi::AgentInstance instance = Akonadi::AgentManager::self()->instance(collection.resource());
if (!instance.isOnline()) {
if (KMessageBox::questionYesNo(parentWidget,
i18n("Before syncing folder \"%1\" it is necessary to have the resource online. Do you want to make it online?", collection.displayName()),
i18n("Account \"%1\" is offline", instance.name()),
KGuiItem(i18nc("@action:button", "Go Online")), KStandardGuiItem::cancel()) != KMessageBox::Yes) {
return false;
}
instance.setIsOnline(true);
}
return true;
}
void slotSynchronizeCollectionRecursive()
{
Q_ASSERT(collectionSelectionModel);
const QModelIndexList list = safeSelectedRows(collectionSelectionModel);
if (list.isEmpty()) {
return;
}
const Collection::List collections = selectedCollections();
if (collections.isEmpty()) {
return;
}
foreach (const Collection &collection, collections) {
if (!testAndSetOnlineResources(collection)) {
break;
}
AgentManager::self()->synchronizeCollection(collection, true);
}
}
void slotCollectionProperties()
{
const QModelIndexList list = safeSelectedRows(collectionSelectionModel);
if (list.isEmpty()) {
return;
}
const QModelIndex index = list.first();
Q_ASSERT(index.isValid());
const Collection collection = index.data(CollectionModel::CollectionRole).value<Collection>();
Q_ASSERT(collection.isValid());
CollectionPropertiesDialog *dlg = new CollectionPropertiesDialog(collection, mCollectionPropertiesPageNames, parentWidget);
dlg->setCaption(contextText(StandardActionManager::CollectionProperties, StandardActionManager::DialogTitle, collection.displayName()));
dlg->show();
}
void slotCopyItems()
{
encodeToClipboard(itemSelectionModel);
}
void slotCutItems()
{
encodeToClipboard(itemSelectionModel, true);
}
void slotPaste()
{
Q_ASSERT(collectionSelectionModel);
const QModelIndexList list = safeSelectedRows(collectionSelectionModel);
if (list.isEmpty()) {
return;
}
const QModelIndex index = list.first();
Q_ASSERT(index.isValid());
#ifndef QT_NO_CLIPBOARD
// TODO: Copy or move? We can't seem to cut yet
QAbstractItemModel *model = const_cast<QAbstractItemModel *>(collectionSelectionModel->model());
const QMimeData *mimeData = QApplication::clipboard()->mimeData();
model->dropMimeData(mimeData, isCutAction(mimeData) ? Qt::MoveAction : Qt::CopyAction, -1, -1, index);
model->setData(QModelIndex(), false, EntityTreeModel::PendingCutRole);
QApplication::clipboard()->clear();
#endif
}
void slotDeleteItems()
{
Q_ASSERT(itemSelectionModel);
Item::List items;
foreach (const QModelIndex &index, safeSelectedRows(itemSelectionModel)) {
bool ok;
const qlonglong id = index.data(ItemModel::IdRole).toLongLong(&ok);
Q_ASSERT(ok);
items << Item(id);
}
if (items.isEmpty()) {
return;
}
QMetaObject::invokeMethod(q, "slotDeleteItemsDeferred",
Qt::QueuedConnection,
Q_ARG(Akonadi::Item::List, items));
}
void slotDeleteItemsDeferred(const Akonadi::Item::List &items)
{
Q_ASSERT(itemSelectionModel);
if (KMessageBox::questionYesNo(parentWidget,
contextText(StandardActionManager::DeleteItems, StandardActionManager::MessageBoxText, items.count(), QString()),
contextText(StandardActionManager::DeleteItems, StandardActionManager::MessageBoxTitle, items.count(), QString()),
KStandardGuiItem::del(), KStandardGuiItem::cancel(),
QString(), KMessageBox::Dangerous) != KMessageBox::Yes) {
return;
}
ItemDeleteJob *job = new ItemDeleteJob(items, q);
q->connect(job, SIGNAL(result(KJob*)), q, SLOT(itemDeletionResult(KJob*)));
}
void slotLocalSubscription()
{
SubscriptionDialog *dlg = new SubscriptionDialog(mMimeTypeFilter, parentWidget);
dlg->showHiddenCollection(true);
dlg->show();
}
void slotAddToFavorites()
{
Q_ASSERT(collectionSelectionModel);
Q_ASSERT(favoritesModel);
const QModelIndexList list = safeSelectedRows(collectionSelectionModel);
if (list.isEmpty()) {
return;
}
foreach (const QModelIndex &index, list) {
Q_ASSERT(index.isValid());
const Collection collection = index.data(CollectionModel::CollectionRole).value<Collection>();
Q_ASSERT(collection.isValid());
favoritesModel->addCollection(collection);
}
updateActions();
}
void slotRemoveFromFavorites()
{
Q_ASSERT(collectionSelectionModel);
Q_ASSERT(favoritesModel);
const QModelIndexList list = safeSelectedRows(collectionSelectionModel);
if (list.isEmpty()) {
return;
}
foreach (const QModelIndex &index, list) {
Q_ASSERT(index.isValid());
const Collection collection = index.data(CollectionModel::CollectionRole).value<Collection>();
Q_ASSERT(collection.isValid());
favoritesModel->removeCollection(collection);
}
updateActions();
}
void slotRenameFavorite()
{
Q_ASSERT(collectionSelectionModel);
Q_ASSERT(favoritesModel);
const QModelIndexList list = safeSelectedRows(collectionSelectionModel);
if (list.isEmpty()) {
return;
}
const QModelIndex index = list.first();
Q_ASSERT(index.isValid());
const Collection collection = index.data(CollectionModel::CollectionRole).value<Collection>();
Q_ASSERT(collection.isValid());
QPointer<RenameFavoriteDialog> dlg(new RenameFavoriteDialog(contextText(StandardActionManager::RenameFavoriteCollection, StandardActionManager::DialogTitle), contextText(StandardActionManager::RenameFavoriteCollection, StandardActionManager::DialogText) , favoritesModel->favoriteLabel(collection), collection.displayName(), parentWidget));
if (dlg->exec() == QDialog::Accepted && dlg != 0) {
favoritesModel->setFavoriteLabel(collection, dlg->newName());
}
delete dlg;
}
void slotSynchronizeFavoriteCollections()
{
Q_ASSERT(favoritesModel);
foreach (const Collection &collection, favoritesModel->collections()) {
// there might be virtual collections in favorites which cannot be checked
// so let's be safe here, agentmanager asserts otherwise
if (!collection.resource().isEmpty()) {
AgentManager::self()->synchronizeCollection(collection, false);
}
}
}
void slotCopyCollectionTo()
{
pasteTo(collectionSelectionModel, collectionSelectionModel->model(), CopyCollectionToMenu, Qt::CopyAction);
}
void slotCopyItemTo()
{
pasteTo(itemSelectionModel, collectionSelectionModel->model(), CopyItemToMenu, Qt::CopyAction);
}
void slotMoveCollectionTo()
{
pasteTo(collectionSelectionModel, collectionSelectionModel->model(), MoveCollectionToMenu, Qt::MoveAction);
}
void slotMoveItemTo()
{
pasteTo(itemSelectionModel, collectionSelectionModel->model(), MoveItemToMenu, Qt::MoveAction);
}
void slotCopyCollectionTo(QAction *action)
{
pasteTo(collectionSelectionModel, action, Qt::CopyAction);
}
void slotCopyItemTo(QAction *action)
{
pasteTo(itemSelectionModel, action, Qt::CopyAction);
}
void slotMoveCollectionTo(QAction *action)
{
pasteTo(collectionSelectionModel, action, Qt::MoveAction);
}
void slotMoveItemTo(QAction *action)
{
pasteTo(itemSelectionModel, action, Qt::MoveAction);
}
AgentInstance::List selectedAgentInstances() const
{
AgentInstance::List instances;
Q_ASSERT(collectionSelectionModel);
if (collectionSelectionModel->selection().indexes().isEmpty()) {
return instances;
}
foreach (const QModelIndex &index, collectionSelectionModel->selection().indexes()) {
Q_ASSERT(index.isValid());
const Collection collection = index.data(CollectionModel::CollectionRole).value<Collection>();
Q_ASSERT(collection.isValid());
if (collection.isValid()) {
const QString identifier = collection.resource();
instances << AgentManager::self()->instance(identifier);
}
}
return instances;
}
AgentInstance selectedAgentInstance() const
{
const AgentInstance::List instances = selectedAgentInstances();
if (instances.isEmpty()) {
return AgentInstance();
}
return instances.first();
}
void slotCreateResource()
{
QPointer<Akonadi::AgentTypeDialog> dlg(new Akonadi::AgentTypeDialog(parentWidget));
dlg->setCaption(contextText(StandardActionManager::CreateResource, StandardActionManager::DialogTitle));
foreach (const QString &mimeType, mMimeTypeFilter) {
dlg->agentFilterProxyModel()->addMimeTypeFilter(mimeType);
}
foreach (const QString &capability, mCapabilityFilter) {
dlg->agentFilterProxyModel()->addCapabilityFilter(capability);
}
if (dlg->exec() == QDialog::Accepted && dlg != 0) {
const AgentType agentType = dlg->agentType();
if (agentType.isValid()) {
AgentInstanceCreateJob *job = new AgentInstanceCreateJob(agentType, q);
q->connect(job, SIGNAL(result(KJob*)), SLOT(resourceCreationResult(KJob*)));
job->configure(parentWidget);
job->start();
}
}
delete dlg;
}
void slotDeleteResource()
{
const AgentInstance::List instances = selectedAgentInstances();
if (instances.isEmpty()) {
return;
}
if (KMessageBox::questionYesNo(parentWidget,
contextText(StandardActionManager::DeleteResources, StandardActionManager::MessageBoxText, instances.count(), instances.first().name()),
contextText(StandardActionManager::DeleteResources, StandardActionManager::MessageBoxTitle, instances.count(), instances.first().name()),
KStandardGuiItem::del(), KStandardGuiItem::cancel(),
QString(), KMessageBox::Dangerous) != KMessageBox::Yes) {
return;
}
foreach (const AgentInstance &instance, instances) {
AgentManager::self()->removeInstance(instance);
}
}
void slotSynchronizeResource()
{
const AgentInstance::List instances = selectedAgentInstances();
if (instances.isEmpty()) {
return;
}
foreach (AgentInstance instance, instances) { //krazy:exclude=foreach
instance.synchronize();
}
}
void slotResourceProperties()
{
AgentInstance instance = selectedAgentInstance();
if (!instance.isValid()) {
return;
}
instance.configure(parentWidget);
}
void slotToggleWorkOffline(bool offline)
{
setWorkOffline(offline);
AgentInstance::List instances = AgentManager::self()->instances();
foreach (AgentInstance instance, instances) { //krazy:exclude=foreach
instance.setIsOnline(!offline);
}
}
void pasteTo(QItemSelectionModel *selectionModel, const QAbstractItemModel *model, StandardActionManager::Type type, Qt::DropAction dropAction)
{
const QSet<QString> mimeTypes = mimeTypesOfSelection(type);
QPointer<CollectionDialog> dlg(new CollectionDialog(const_cast<QAbstractItemModel *>(model)));
dlg->setMimeTypeFilter(mimeTypes.toList());
if (type == CopyItemToMenu || type == MoveItemToMenu) {
dlg->setAccessRightsFilter(Collection::CanCreateItem);
} else if (type == CopyCollectionToMenu || type == MoveCollectionToMenu) {
dlg->setAccessRightsFilter(Collection::CanCreateCollection);
}
if (dlg->exec() == QDialog::Accepted && dlg != 0) {
const QModelIndex index = EntityTreeModel::modelIndexForCollection(collectionSelectionModel->model(), dlg->selectedCollection());
if (!index.isValid()) {
return;
}
const QMimeData *mimeData = selectionModel->model()->mimeData(safeSelectedRows(selectionModel));
QAbstractItemModel *model = const_cast<QAbstractItemModel *>(index.model());
model->dropMimeData(mimeData, dropAction, -1, -1, index);
}
delete dlg;
}
void pasteTo(QItemSelectionModel *selectionModel, QAction *action, Qt::DropAction dropAction)
{
Q_ASSERT(selectionModel);
Q_ASSERT(action);
if (safeSelectedRows(selectionModel).count() <= 0) {
return;
}
const QMimeData *mimeData = selectionModel->model()->mimeData(selectionModel->selectedRows());
const QModelIndex index = action->data().value<QModelIndex>();
Q_ASSERT(index.isValid());
QAbstractItemModel *model = const_cast<QAbstractItemModel *>(index.model());
const Collection collection = index.data(EntityTreeModel::CollectionRole).value<Collection>();
addRecentCollection(collection.id());
model->dropMimeData(mimeData, dropAction, -1, -1, index);
}
void addRecentCollection(Akonadi::Collection::Id id)
{
QMapIterator<StandardActionManager::Type, QWeakPointer<RecentCollectionAction> > item(mRecentCollectionsMenu);
while (item.hasNext()) {
item.next();
if (item.value().data()) {
item.value().data()->addRecentCollection(item.key(),id);
}
}
}
void collectionCreationResult(KJob *job)
{
if (job->error()) {
KMessageBox::error(parentWidget,
contextText(StandardActionManager::CreateCollection, StandardActionManager::ErrorMessageText, job->errorString()),
contextText(StandardActionManager::CreateCollection, StandardActionManager::ErrorMessageTitle));
}
}
void collectionDeletionResult(KJob *job)
{
if (job->error()) {
KMessageBox::error(parentWidget,
contextText(StandardActionManager::DeleteCollections, StandardActionManager::ErrorMessageText, job->errorString()),
contextText(StandardActionManager::DeleteCollections, StandardActionManager::ErrorMessageTitle));
}
}
void moveCollectionToTrashResult(KJob *job)
{
if (job->error()) {
KMessageBox::error(parentWidget,
contextText(StandardActionManager::MoveCollectionsToTrash, StandardActionManager::ErrorMessageText, job->errorString()),
contextText(StandardActionManager::MoveCollectionsToTrash, StandardActionManager::ErrorMessageTitle));
}
}
void moveItemToTrashResult(KJob *job)
{
if (job->error()) {
KMessageBox::error(parentWidget,
contextText(StandardActionManager::MoveItemsToTrash, StandardActionManager::ErrorMessageText, job->errorString()),
contextText(StandardActionManager::MoveItemsToTrash, StandardActionManager::ErrorMessageTitle));
}
}
void itemDeletionResult(KJob *job)
{
if (job->error()) {
KMessageBox::error(parentWidget,
contextText(StandardActionManager::DeleteItems, StandardActionManager::ErrorMessageText, job->errorString()),
contextText(StandardActionManager::DeleteItems, StandardActionManager::ErrorMessageTitle));
}
}
void resourceCreationResult(KJob *job)
{
if (job->error()) {
KMessageBox::error(parentWidget,
contextText(StandardActionManager::CreateResource, StandardActionManager::ErrorMessageText, job->errorString()),
contextText(StandardActionManager::CreateResource, StandardActionManager::ErrorMessageTitle));
}
}
void pasteResult(KJob *job)
{
if (job->error()) {
KMessageBox::error(parentWidget,
contextText(StandardActionManager::Paste, StandardActionManager::ErrorMessageText, job->errorString()),
contextText(StandardActionManager::Paste, StandardActionManager::ErrorMessageTitle));
}
}
/**
* Returns a set of mime types of the entities that are currently selected.
*/
QSet<QString> mimeTypesOfSelection(StandardActionManager::Type type) const
{
QModelIndexList list;
QSet<QString> mimeTypes;
const bool isItemAction = (type == CopyItemToMenu || type == MoveItemToMenu);
const bool isCollectionAction = (type == CopyCollectionToMenu || type == MoveCollectionToMenu);
if (isItemAction) {
list = safeSelectedRows(itemSelectionModel);
foreach (const QModelIndex &index, list) {
mimeTypes << index.data(EntityTreeModel::MimeTypeRole).toString();
}
}
if (isCollectionAction) {
list = safeSelectedRows(collectionSelectionModel);
foreach (const QModelIndex &index, list) {
const Collection collection = index.data(EntityTreeModel::CollectionRole).value<Collection>();
// The mimetypes that the selected collection can possibly contain
mimeTypes = AgentManager::self()->instance(collection.resource()).type().mimeTypes().toSet();
}
}
return mimeTypes;
}
/**
* Returns whether items with the given @p mimeTypes can be written to the given @p collection.
*/
bool isWritableTargetCollectionForMimeTypes(const Collection &collection, const QSet<QString> &mimeTypes, StandardActionManager::Type type) const
{
if (collection.isVirtual()) {
return false;
}
const bool isItemAction = (type == CopyItemToMenu || type == MoveItemToMenu);
const bool isCollectionAction = (type == CopyCollectionToMenu || type == MoveCollectionToMenu);
const bool canContainRequiredMimeTypes = !collection.contentMimeTypes().toSet().intersect(mimeTypes).isEmpty();
const bool canCreateNewItems = (collection.rights() & Collection::CanCreateItem);
const bool canCreateNewCollections = (collection.rights() & Collection::CanCreateCollection);
const bool canContainCollections = collection.contentMimeTypes().contains(Collection::mimeType()) || collection.contentMimeTypes().contains(Collection::virtualMimeType());
const bool resourceAllowsRequiredMimeTypes = AgentManager::self()->instance(collection.resource()).type().mimeTypes().toSet().contains(mimeTypes);
const bool isReadOnlyForItems = (isItemAction && (!canCreateNewItems || !canContainRequiredMimeTypes));
const bool isReadOnlyForCollections = (isCollectionAction && (!canCreateNewCollections || !canContainCollections || !resourceAllowsRequiredMimeTypes));
return !(CollectionUtils::isStructural(collection) || isReadOnlyForItems || isReadOnlyForCollections);
}
void fillFoldersMenu(const Akonadi::Collection::List &selectedCollectionsList, const QSet<QString> &mimeTypes, StandardActionManager::Type type, QMenu *menu,
const QAbstractItemModel *model, QModelIndex parentIndex)
{
const int rowCount = model->rowCount(parentIndex);
for (int row = 0; row < rowCount; ++row) {
const QModelIndex index = model->index(row, 0, parentIndex);
const Collection collection = model->data(index, CollectionModel::CollectionRole).value<Collection>();
if (collection.isVirtual()) {
continue;
}
const bool readOnly = !isWritableTargetCollectionForMimeTypes( collection, mimeTypes, type );
const bool collectionIsSelected = selectedCollectionsList.contains( collection );
if (type == MoveCollectionToMenu && collectionIsSelected) {
continue;
}
QString label = model->data(index).toString();
label.replace(QLatin1String("&"), QLatin1String("&&"));
const QIcon icon = model->data(index, Qt::DecorationRole).value<QIcon>();
if (model->rowCount(index) > 0) {
// new level
QMenu *popup = new QMenu(menu);
const bool moveAction = (type == MoveCollectionToMenu || type == MoveItemToMenu);
popup->setObjectName(QString::fromUtf8("subMenu"));
popup->setTitle(label);
popup->setIcon(icon);
fillFoldersMenu(selectedCollectionsList, mimeTypes, type, popup, model, index);
if (!(type == CopyCollectionToMenu && collectionIsSelected)) {
if ( !readOnly ) {
popup->addSeparator();
QAction *action = popup->addAction( moveAction ? i18n( "Move to This Folder" ) : i18n( "Copy to This Folder" ) );
action->setData( QVariant::fromValue<QModelIndex>( index ) );
}
}
menu->addMenu(popup);
} else {
// insert an item
QAction *action = menu->addAction(icon, label);
action->setData(QVariant::fromValue<QModelIndex>(index));
action->setEnabled(!readOnly && !collectionIsSelected);
}
}
}
void checkModelsConsistency()
{
if (favoritesModel == 0 || favoriteSelectionModel == 0) {
// No need to check when the favorite collections feature is not used
return;
}
// find the base ETM of the favourites view
const QAbstractItemModel *favModel = favoritesModel;
while (const QAbstractProxyModel *proxy = qobject_cast<const QAbstractProxyModel *>(favModel)) {
favModel = proxy->sourceModel();
}
// Check that the collection selection model maps to the same
// EntityTreeModel than favoritesModel
if (collectionSelectionModel != 0) {
const QAbstractItemModel *model = collectionSelectionModel->model();
while (const QAbstractProxyModel *proxy = qobject_cast<const QAbstractProxyModel *>(model)) {
model = proxy->sourceModel();
}
Q_ASSERT(model == favModel);
}
// Check that the favorite selection model maps to favoritesModel
const QAbstractItemModel *model = favoriteSelectionModel->model();
while (const QAbstractProxyModel *proxy = qobject_cast<const QAbstractProxyModel *>(model)) {
model = proxy->sourceModel();
}
Q_ASSERT(model == favModel);
}
void markCutAction(QMimeData *mimeData, bool cut) const
{
if (!cut) {
return;
}
const QByteArray cutSelectionData = "1"; //krazy:exclude=doublequote_chars
mimeData->setData(QLatin1String("application/x-kde.akonadi-cutselection"), cutSelectionData);
}
bool isCutAction(const QMimeData *mimeData) const
{
const QByteArray data = mimeData->data(QLatin1String("application/x-kde.akonadi-cutselection"));
if (data.isEmpty()) {
return false;
} else {
return (data.at(0) == '1'); // true if 1
}
}
void setContextText(StandardActionManager::Type type, StandardActionManager::TextContext context, const QString &data)
{
ContextTextEntry entry;
entry.text = data;
contextTexts[type].insert(context, entry);
}
void setContextText(StandardActionManager::Type type, StandardActionManager::TextContext context, const KLocalizedString &data)
{
ContextTextEntry entry;
entry.localizedText = data;
contextTexts[type].insert(context, entry);
}
QString contextText(StandardActionManager::Type type, StandardActionManager::TextContext context) const
{
return contextTexts[type].value(context).text;
}
QString contextText(StandardActionManager::Type type, StandardActionManager::TextContext context, const QString &value) const
{
KLocalizedString text = contextTexts[type].value(context).localizedText;
if (text.isEmpty()) {
return contextTexts[type].value(context).text;
}
return text.subs(value).toString();
}
QString contextText(StandardActionManager::Type type, StandardActionManager::TextContext context, int count, const QString &value) const
{
KLocalizedString text = contextTexts[type].value(context).localizedText;
if (text.isEmpty()) {
return contextTexts[type].value(context).text;
}
const QString str = text.subs(count).toString();
const int argCount = str.count(QRegExp(QLatin1String("%[0-9]")));
if (argCount > 0) {
return text.subs(count).subs(value).toString();
} else {
return text.subs(count).toString();
}
}
StandardActionManager *q;
KActionCollection *actionCollection;
QWidget *parentWidget;
QItemSelectionModel *collectionSelectionModel;
QItemSelectionModel *itemSelectionModel;
FavoriteCollectionsModel *favoritesModel;
QItemSelectionModel *favoriteSelectionModel;
bool insideSelectionSlot;
QVector<KAction *> actions;
QHash<StandardActionManager::Type, KLocalizedString> pluralLabels;
QHash<StandardActionManager::Type, KLocalizedString> pluralIconLabels;
struct ContextTextEntry
{
QString text;
KLocalizedString localizedText;
bool isLocalized;
};
typedef QHash<StandardActionManager::TextContext, ContextTextEntry> ContextTexts;
QHash<StandardActionManager::Type, ContextTexts> contextTexts;
ActionStateManager mActionStateManager;
QStringList mMimeTypeFilter;
QStringList mCapabilityFilter;
QStringList mCollectionPropertiesPageNames;
QMap<StandardActionManager::Type, QWeakPointer<RecentCollectionAction> > mRecentCollectionsMenu;
};
//@endcond
StandardActionManager::StandardActionManager(KActionCollection *actionCollection, QWidget *parent)
: QObject(parent)
, d(new Private(this))
{
d->parentWidget = parent;
d->actionCollection = actionCollection;
d->mActionStateManager.setReceiver(this);
#ifndef QT_NO_CLIPBOARD
connect(QApplication::clipboard(), SIGNAL(changed(QClipboard::Mode)), SLOT(clipboardChanged(QClipboard::Mode)));
#endif
}
StandardActionManager::~ StandardActionManager()
{
delete d;
}
void StandardActionManager::setCollectionSelectionModel(QItemSelectionModel *selectionModel)
{
d->collectionSelectionModel = selectionModel;
connect(selectionModel, SIGNAL(selectionChanged(QItemSelection,QItemSelection)),
SLOT(collectionSelectionChanged()));
d->checkModelsConsistency();
}
void StandardActionManager::setItemSelectionModel(QItemSelectionModel *selectionModel)
{
d->itemSelectionModel = selectionModel;
connect(selectionModel, SIGNAL(selectionChanged(QItemSelection,QItemSelection)),
SLOT(updateActions()));
}
void StandardActionManager::setFavoriteCollectionsModel(FavoriteCollectionsModel *favoritesModel)
{
d->favoritesModel = favoritesModel;
d->checkModelsConsistency();
}
void StandardActionManager::setFavoriteSelectionModel(QItemSelectionModel *selectionModel)
{
d->favoriteSelectionModel = selectionModel;
connect(selectionModel, SIGNAL(selectionChanged(QItemSelection,QItemSelection)),
SLOT(favoriteSelectionChanged()));
d->checkModelsConsistency();
}
KAction *StandardActionManager::createAction(Type type)
{
Q_ASSERT(type < LastType);
if (d->actions[type]) {
return d->actions[type];
}
KAction *action = 0;
switch (standardActionData[type].actionType) {
case NormalAction:
case ActionWithAlternative:
action = new KAction(d->parentWidget);
break;
case ActionAlternative:
d->actions[type] = d->actions[type - 1];
Q_ASSERT(d->actions[type]);
if ((LastType > type + 1) && (standardActionData[type + 1].actionType == ActionAlternative)) {
createAction(static_cast<Type>(type + 1)); //ensure that alternative actions are initialized when not created by createAllActions
}
return d->actions[type];
case MenuAction:
action = new KActionMenu(d->parentWidget);
break;
case ToggleAction:
action = new KToggleAction(d->parentWidget);
break;
}
if (d->pluralLabels.contains(type) && !d->pluralLabels.value(type).isEmpty()) {
action->setText(d->pluralLabels.value(type).subs(1).toString());
} else if (standardActionData[type].label) {
action->setText(i18n(standardActionData[type].label));
}
if (d->pluralIconLabels.contains(type) && !d->pluralIconLabels.value(type).isEmpty()) {
action->setIconText(d->pluralIconLabels.value(type).subs(1).toString());
} else if (standardActionData[type].iconLabel) {
action->setIconText(i18n(standardActionData[type].iconLabel));
}
if (standardActionData[type].icon) {
action->setIcon(KIcon(QString::fromLatin1(standardActionData[type].icon)));
}
action->setShortcut(standardActionData[type].shortcut);
if (standardActionData[type].slot) {
switch (standardActionData[type].actionType) {
case NormalAction:
case ActionWithAlternative:
connect(action, SIGNAL(triggered()), standardActionData[type].slot);
break;
case MenuAction: {
KActionMenu *actionMenu = qobject_cast<KActionMenu *>(action);
connect(actionMenu->menu(), SIGNAL(triggered(QAction*)), standardActionData[type].slot);
break;
}
case ToggleAction: {
connect(action, SIGNAL(triggered(bool)), standardActionData[type].slot);
break;
}
case ActionAlternative:
Q_ASSERT(0);
}
}
if (type == ToggleWorkOffline) {
// inititalize the action state with information from config file
disconnect(action, SIGNAL(triggered(bool)), this, standardActionData[type].slot);
action->setChecked(workOffline());
connect(action, SIGNAL(triggered(bool)), this, standardActionData[type].slot);
//TODO: find a way to check for updates to the config file
}
Q_ASSERT(standardActionData[type].name);
d->actionCollection->addAction(QString::fromLatin1(standardActionData[type].name), action);
d->actions[type] = action;
if ((standardActionData[type].actionType == ActionWithAlternative) && (standardActionData[type + 1].actionType == ActionAlternative)) {
createAction(static_cast<Type>(type + 1)); //ensure that alternative actions are initialized when not created by createAllActions
}
d->updateActions();
return action;
}
void StandardActionManager::createAllActions()
{
for (uint i = 0; i < LastType; ++i) {
createAction((Type)i);
}
}
KAction *StandardActionManager::action(Type type) const
{
Q_ASSERT(type < LastType);
return d->actions[type];
}
void StandardActionManager::setActionText(Type type, const KLocalizedString &text)
{
Q_ASSERT(type < LastType);
d->pluralLabels.insert(type, text);
d->updateActions();
}
void StandardActionManager::interceptAction(Type type, bool intercept)
{
Q_ASSERT(type < LastType);
const KAction *action = d->actions[type];
if (!action) {
return;
}
if (intercept) {
disconnect(action, SIGNAL(triggered()), this, standardActionData[type].slot);
} else {
connect(action, SIGNAL(triggered()), standardActionData[type].slot);
}
}
Akonadi::Collection::List StandardActionManager::selectedCollections() const
{
Collection::List collections;
if (!d->collectionSelectionModel) {
return collections;
}
foreach (const QModelIndex &index, safeSelectedRows(d->collectionSelectionModel)) {
const Collection collection = index.data(EntityTreeModel::CollectionRole).value<Collection>();
if (collection.isValid()) {
collections << collection;
}
}
return collections;
}
Item::List StandardActionManager::selectedItems() const
{
Item::List items;
if (!d->itemSelectionModel) {
return items;
}
foreach (const QModelIndex &index, safeSelectedRows(d->itemSelectionModel)) {
const Item item = index.data(EntityTreeModel::ItemRole).value<Item>();
if (item.isValid()) {
items << item;
}
}
return items;
}
void StandardActionManager::setContextText(Type type, TextContext context, const QString &text)
{
d->setContextText(type, context, text);
}
void StandardActionManager::setContextText(Type type, TextContext context, const KLocalizedString &text)
{
d->setContextText(type, context, text);
}
void StandardActionManager::setMimeTypeFilter(const QStringList &mimeTypes)
{
d->mMimeTypeFilter = mimeTypes;
}
void StandardActionManager::setCapabilityFilter(const QStringList &capabilities)
{
d->mCapabilityFilter = capabilities;
}
void StandardActionManager::setCollectionPropertiesPageNames(const QStringList &names)
{
d->mCollectionPropertiesPageNames = names;
}
void StandardActionManager::createActionFolderMenu(QMenu *menu, Type type)
{
d->createActionFolderMenu(menu, type);
}
#include "moc_standardactionmanager.cpp"
|