| 95 | } |
| 96 | |
| 97 | bool Resource::enable(EnableAction action) |
| 98 | { |
| 99 | if (m_type == ResourceType::UNKNOWN || m_type == ResourceType::FOLDER) |
| 100 | return false; |
| 101 | |
| 102 | |
| 103 | QString path = m_file_info.absoluteFilePath(); |
| 104 | QFile file(path); |
| 105 | |
| 106 | bool enable = true; |
| 107 | switch (action) { |
| 108 | case EnableAction::ENABLE: |
| 109 | enable = true; |
| 110 | break; |
| 111 | case EnableAction::DISABLE: |
| 112 | enable = false; |
| 113 | break; |
| 114 | case EnableAction::TOGGLE: |
| 115 | default: |
| 116 | enable = !enabled(); |
| 117 | break; |
| 118 | } |
| 119 | |
| 120 | if (m_enabled == enable) |
| 121 | return false; |
| 122 | |
| 123 | if (enable) { |
| 124 | // m_enabled is false, but there's no '.disabled' suffix. |
| 125 | // TODO: Report error? |
| 126 | if (!path.endsWith(".disabled")) |
| 127 | return false; |
| 128 | path.chop(9); |
| 129 | |
| 130 | if (!file.rename(path)) |
| 131 | return false; |
| 132 | } else { |
| 133 | path += ".disabled"; |
| 134 | |
| 135 | if (!file.rename(path)) |
| 136 | return false; |
| 137 | } |
| 138 | |
| 139 | setFile(QFileInfo(path)); |
| 140 | |
| 141 | m_enabled = enable; |
| 142 | return true; |
| 143 | } |
| 144 | |
| 145 | bool Resource::destroy() |
| 146 | { |