Changeset View
Changeset View
Standalone View
Standalone View
src/BookmarkHandler.cpp
Show First 20 Lines • Show All 60 Lines • ▼ Show 20 Line(s) | 60 | _file = QStandardPaths::writableLocation(QStandardPaths::GenericDataLocation) | |||
---|---|---|---|---|---|
61 | + QStringLiteral("/konsole"); | 61 | + QStringLiteral("/konsole"); | ||
62 | QDir().mkpath(_file); | 62 | QDir().mkpath(_file); | ||
63 | _file += QStringLiteral("/bookmarks.xml"); | 63 | _file += QStringLiteral("/bookmarks.xml"); | ||
64 | } | 64 | } | ||
65 | 65 | | |||
66 | KBookmarkManager *manager = KBookmarkManager::managerForFile(_file, QStringLiteral("konsole")); | 66 | KBookmarkManager *manager = KBookmarkManager::managerForFile(_file, QStringLiteral("konsole")); | ||
67 | 67 | | |||
68 | manager->setUpdate(true); | 68 | manager->setUpdate(true); | ||
69 | 69 | _bookmarkMenu = new KBookmarkMenu(manager, this, _menu, toplevel ? collection : nullptr); | |||
70 | if (toplevel) { | | |||
71 | _bookmarkMenu = new KBookmarkMenu(manager, this, _menu, collection); | | |||
72 | } else { | | |||
73 | _bookmarkMenu = new KBookmarkMenu(manager, this, _menu, nullptr); | | |||
74 | } | | |||
75 | } | 70 | } | ||
76 | 71 | | |||
77 | BookmarkHandler::~BookmarkHandler() | 72 | BookmarkHandler::~BookmarkHandler() | ||
78 | { | 73 | { | ||
79 | delete _bookmarkMenu; | 74 | delete _bookmarkMenu; | ||
80 | } | 75 | } | ||
81 | 76 | | |||
82 | void BookmarkHandler::openBookmark(const KBookmark &bm, Qt::MouseButtons, Qt::KeyboardModifiers) | 77 | void BookmarkHandler::openBookmark(const KBookmark &bm, Qt::MouseButtons, Qt::KeyboardModifiers) | ||
83 | { | 78 | { | ||
84 | emit openUrl(bm.url()); | 79 | emit openUrl(bm.url()); | ||
85 | } | 80 | } | ||
86 | 81 | | |||
87 | void BookmarkHandler::openFolderinTabs(const KBookmarkGroup &group) | 82 | void BookmarkHandler::openFolderinTabs(const KBookmarkGroup &group) | ||
88 | { | 83 | { | ||
89 | emit openUrls(group.groupUrlList()); | 84 | emit openUrls(group.groupUrlList()); | ||
90 | } | 85 | } | ||
91 | 86 | | |||
92 | bool BookmarkHandler::enableOption(BookmarkOption option) const | 87 | bool BookmarkHandler::enableOption(BookmarkOption option) const | ||
93 | { | 88 | { | ||
94 | if (option == ShowAddBookmark || option == ShowEditBookmark) { | 89 | if (option == ShowAddBookmark || option == ShowEditBookmark) { | ||
95 | return _toplevel; | 90 | return _toplevel; | ||
96 | } else { | | |||
97 | return KBookmarkOwner::enableOption(option); | | |||
98 | } | 91 | } | ||
92 | return KBookmarkOwner::enableOption(option); | ||||
99 | } | 93 | } | ||
100 | 94 | | |||
101 | QUrl BookmarkHandler::currentUrl() const | 95 | QUrl BookmarkHandler::currentUrl() const | ||
102 | { | 96 | { | ||
103 | return urlForView(_activeView); | 97 | return urlForView(_activeView); | ||
104 | } | 98 | } | ||
105 | 99 | | |||
106 | QUrl BookmarkHandler::urlForView(ViewProperties *view) const | 100 | QUrl BookmarkHandler::urlForView(ViewProperties *view) const | ||
107 | { | 101 | { | ||
108 | if (view != nullptr) { | 102 | if (view != nullptr) { | ||
109 | return view->url(); | 103 | return view->url(); | ||
110 | } else { | | |||
111 | return QUrl(); | | |||
112 | } | 104 | } | ||
105 | return {}; | ||||
ngraham: Why not an empty `QUrl()`? | |||||
The author is trying to use return {} feature in C++ 11. However, QUrl() is more explicit for those who does or doesn't know about the previously mentioned feature. Explicit is better then Implicit. ahmedbilal: The author is trying to use [[ https://stackoverflow.com/questions/39487065/what-does-return… | |||||
113 | } | 106 | } | ||
114 | 107 | | |||
115 | QString BookmarkHandler::currentTitle() const | 108 | QString BookmarkHandler::currentTitle() const | ||
116 | { | 109 | { | ||
117 | return titleForView(_activeView); | 110 | return titleForView(_activeView); | ||
118 | } | 111 | } | ||
119 | 112 | | |||
120 | QString BookmarkHandler::titleForView(ViewProperties *view) const | 113 | QString BookmarkHandler::titleForView(ViewProperties *view) const | ||
121 | { | 114 | { | ||
122 | const QUrl &url = view != nullptr ? view->url() : QUrl(); | 115 | const QUrl &url = view != nullptr ? view->url() : QUrl(); | ||
123 | if (url.isLocalFile()) { | 116 | if (url.isLocalFile()) { | ||
124 | QString path = url.path(); | 117 | QString path = url.path(); | ||
125 | 118 | | |||
126 | path = KShell::tildeExpand(path); | 119 | path = KShell::tildeExpand(path); | ||
127 | path = QFileInfo(path).completeBaseName(); | 120 | path = QFileInfo(path).completeBaseName(); | ||
128 | 121 | | |||
129 | return path; | 122 | return path; | ||
130 | } else if (!url.host().isEmpty()) { | 123 | } | ||
124 | if (!url.host().isEmpty()) { | ||||
131 | if (!url.userName().isEmpty()) { | 125 | if (!url.userName().isEmpty()) { | ||
132 | return i18nc("@item:inmenu The user's name and host they are connected to via ssh", | 126 | return i18nc("@item:inmenu The user's name and host they are connected to via ssh", | ||
133 | "%1 on %2", url.userName(), url.host()); | 127 | "%1 on %2", url.userName(), url.host()); | ||
134 | } else { | | |||
135 | return i18nc("@item:inmenu The host the user is connected to via ssh", "%1", | | |||
136 | url.host()); | | |||
137 | } | 128 | } | ||
129 | return i18nc("@item:inmenu The host the user is connected to via ssh", "%1", url.host()); | ||||
138 | } | 130 | } | ||
139 | 131 | | |||
140 | return url.toDisplayString(); | 132 | return url.toDisplayString(); | ||
141 | } | 133 | } | ||
142 | 134 | | |||
143 | QString BookmarkHandler::currentIcon() const | 135 | QString BookmarkHandler::currentIcon() const | ||
144 | { | 136 | { | ||
145 | return iconForView(_activeView); | 137 | return iconForView(_activeView); | ||
146 | } | 138 | } | ||
147 | 139 | | |||
148 | QString BookmarkHandler::iconForView(ViewProperties *view) const | 140 | QString BookmarkHandler::iconForView(ViewProperties *view) const | ||
149 | { | 141 | { | ||
150 | if (view != nullptr) { | 142 | if (view != nullptr) { | ||
151 | return view->icon().name(); | 143 | return view->icon().name(); | ||
152 | } else { | | |||
153 | return QString(); | | |||
154 | } | 144 | } | ||
145 | return {}; | ||||
ngraham: Why not an empty `QString()`? | |||||
155 | } | 146 | } | ||
156 | 147 | | |||
157 | bool BookmarkHandler::supportsTabs() const | 148 | bool BookmarkHandler::supportsTabs() const | ||
158 | { | 149 | { | ||
159 | return true; | 150 | return true; | ||
160 | } | 151 | } | ||
161 | 152 | | |||
162 | QList<KBookmarkOwner::FutureBookmark> BookmarkHandler::currentBookmarkList() const | 153 | QList<KBookmarkOwner::FutureBookmark> BookmarkHandler::currentBookmarkList() const | ||
Show All 30 Lines |
Why not an empty QUrl()?