Changeset View
Changeset View
Standalone View
Standalone View
krusader/BookMan/krbookmark.cpp
Show All 22 Lines | |||||
23 | #include "../krglobal.h" | 23 | #include "../krglobal.h" | ||
24 | #include "../icon.h" | 24 | #include "../icon.h" | ||
25 | #include "../Archive/krarchandler.h" | 25 | #include "../Archive/krarchandler.h" | ||
26 | #include "../FileSystem/krtrashhandler.h" | 26 | #include "../FileSystem/krtrashhandler.h" | ||
27 | #include "../Panel/listpanelactions.h" | 27 | #include "../Panel/listpanelactions.h" | ||
28 | 28 | | |||
29 | #include <KI18n/KLocalizedString> | 29 | #include <KI18n/KLocalizedString> | ||
30 | #include <KXmlGui/KActionCollection> | 30 | #include <KXmlGui/KActionCollection> | ||
31 | #include <utility> | ||||
31 | 32 | | |||
32 | #define BM_NAME(X) (QString("Bookmark:")+X) | 33 | #define BM_NAME(X) (QString("Bookmark:")+X) | ||
33 | 34 | | |||
34 | static const char* NAME_TRASH = I18N_NOOP("Trash bin"); | 35 | static const char* NAME_TRASH = I18N_NOOP("Trash bin"); | ||
35 | static const char* NAME_VIRTUAL = I18N_NOOP("Virtual Filesystem"); | 36 | static const char* NAME_VIRTUAL = I18N_NOOP("Virtual Filesystem"); | ||
36 | static const char* NAME_LAN = I18N_NOOP("Local Network"); | 37 | static const char* NAME_LAN = I18N_NOOP("Local Network"); | ||
37 | 38 | | |||
38 | KrBookmark::KrBookmark(QString name, QUrl url, KActionCollection *parent, QString iconName, QString actionName) : | 39 | KrBookmark::KrBookmark(const QString& name, QUrl url, KActionCollection *parent, const QString& iconName, const QString& actionName) : | ||
39 | QAction(parent), _url(url), _iconName(iconName), _folder(false), _separator(false), _autoDelete(true) | 40 | QAction(parent), _url(std::move(url)), _iconName(iconName), _folder(false), _separator(false), _autoDelete(true) | ||
40 | { | 41 | { | ||
41 | QString actName = actionName.isNull() ? BM_NAME(name) : BM_NAME(actionName); | 42 | QString actName = actionName.isNull() ? BM_NAME(name) : BM_NAME(actionName); | ||
42 | setText(name); | 43 | setText(name); | ||
43 | parent->addAction(actName, this); | 44 | parent->addAction(actName, this); | ||
44 | connect(this, SIGNAL(triggered()), this, SLOT(activatedProxy())); | 45 | connect(this, SIGNAL(triggered()), this, SLOT(activatedProxy())); | ||
45 | 46 | | |||
46 | setIconName(iconName); | 47 | setIconName(iconName); | ||
47 | } | 48 | } | ||
48 | 49 | | |||
49 | KrBookmark::KrBookmark(QString name, QString iconName) : | 50 | KrBookmark::KrBookmark(const QString& name, const QString& iconName) : | ||
50 | QAction(Icon(iconName), name, 0), _iconName(iconName), _folder(true), _separator(false), _autoDelete(false) | 51 | QAction(Icon(iconName), name, nullptr), _iconName(iconName), _folder(true), _separator(false), _autoDelete(false) | ||
51 | { | 52 | { | ||
52 | setIcon(Icon(iconName == "" ? "folder" : iconName)); | 53 | setIcon(Icon(iconName == "" ? "folder" : iconName)); | ||
53 | } | 54 | } | ||
54 | 55 | | |||
55 | KrBookmark::~KrBookmark() | 56 | KrBookmark::~KrBookmark() | ||
56 | { | 57 | { | ||
57 | if (_autoDelete) { | 58 | if (_autoDelete) { | ||
58 | QListIterator<KrBookmark *> it(_children); | 59 | QListIterator<KrBookmark *> it(_children); | ||
59 | while (it.hasNext()) | 60 | while (it.hasNext()) | ||
60 | delete it.next(); | 61 | delete it.next(); | ||
61 | _children.clear(); | 62 | _children.clear(); | ||
62 | } | 63 | } | ||
63 | } | 64 | } | ||
64 | 65 | | |||
65 | void KrBookmark::setIconName(QString iconName) | 66 | void KrBookmark::setIconName(const QString& iconName) | ||
66 | { | 67 | { | ||
67 | if (!iconName.isEmpty()) { | 68 | if (!iconName.isEmpty()) { | ||
68 | setIcon(Icon(iconName)); | 69 | setIcon(Icon(iconName)); | ||
69 | } else if (_url.isLocalFile()) { | 70 | } else if (_url.isLocalFile()) { | ||
70 | setIcon(Icon("folder")); | 71 | setIcon(Icon("folder")); | ||
71 | } else if (KRarcHandler::isArchive(_url)) { | 72 | } else if (KRarcHandler::isArchive(_url)) { | ||
72 | setIcon(Icon("application-x-tar")); | 73 | setIcon(Icon("application-x-tar")); | ||
73 | } else { | 74 | } else { | ||
74 | setIcon(Icon("folder-html")); | 75 | setIcon(Icon("folder-html")); | ||
75 | } | 76 | } | ||
76 | } | 77 | } | ||
77 | 78 | | |||
78 | KrBookmark * KrBookmark::getExistingBookmark(QString actionName, KActionCollection *collection) | 79 | KrBookmark * KrBookmark::getExistingBookmark(const QString& actionName, KActionCollection *collection) | ||
79 | { | 80 | { | ||
80 | return static_cast<KrBookmark*>(collection->action(BM_NAME(actionName))); | 81 | return dynamic_cast<KrBookmark*>(collection->action(BM_NAME(actionName))); | ||
81 | } | 82 | } | ||
82 | 83 | | |||
83 | KrBookmark * KrBookmark::trash(KActionCollection *collection) | 84 | KrBookmark * KrBookmark::trash(KActionCollection *collection) | ||
84 | { | 85 | { | ||
85 | KrBookmark *bm = getExistingBookmark(i18n(NAME_TRASH), collection); | 86 | KrBookmark *bm = getExistingBookmark(i18n(NAME_TRASH), collection); | ||
86 | if (!bm) | 87 | if (!bm) | ||
87 | bm = new KrBookmark(i18n(NAME_TRASH), QUrl("trash:/"), collection); | 88 | bm = new KrBookmark(i18n(NAME_TRASH), QUrl("trash:/"), collection); | ||
88 | 89 | | |||
▲ Show 20 Lines • Show All 63 Lines • Show Last 20 Lines |