Changeset View
Changeset View
Standalone View
Standalone View
gmenu-dbusmenu-proxy/utils.cpp
- This file was added.
1 | /* | ||||
---|---|---|---|---|---|
2 | * Copyright (C) 2018 Kai Uwe Broulik <kde@privat.broulik.de> | ||||
3 | * | ||||
4 | * This library is free software; you can redistribute it and/or | ||||
5 | * modify it under the terms of the GNU Lesser General Public | ||||
6 | * License as published by the Free Software Foundation; either | ||||
7 | * version 2.1 of the License, or (at your option) any later version. | ||||
8 | * | ||||
9 | * This library is distributed in the hope that it will be useful, | ||||
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||||
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||||
12 | * Lesser General Public License for more details. | ||||
13 | * | ||||
14 | * You should have received a copy of the GNU Lesser General Public | ||||
15 | * License along with this library; if not, write to the Free Software | ||||
16 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA | ||||
17 | * | ||||
18 | */ | ||||
19 | | ||||
20 | #include "utils.h" | ||||
21 | | ||||
22 | int Utils::treeStructureToInt(int subscription, int section, int index) | ||||
23 | { | ||||
24 | return subscription * 1000000 + section * 1000 + index; | ||||
25 | } | ||||
26 | | ||||
27 | void Utils::intToTreeStructure(int source, int &subscription, int §ion, int &index) | ||||
28 | { | ||||
29 | // TODO some better math :) or bit shifting or something | ||||
30 | index = source % 1000; | ||||
31 | section = (source / 1000) % 1000; | ||||
32 | subscription = source / 1000000; | ||||
33 | } | ||||
34 | | ||||
35 | QString Utils::itemActionName(const QVariantMap &item) | ||||
36 | { | ||||
37 | QString actionName = item.value(QStringLiteral("action")).toString(); | ||||
38 | if (actionName.isEmpty()) { | ||||
39 | actionName = item.value(QStringLiteral("submenu-action")).toString(); | ||||
40 | } | ||||
41 | return actionName; | ||||
42 | } |