-
Notifications
You must be signed in to change notification settings - Fork 33
Improve mime type deployment #135
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
azubieta
wants to merge
18
commits into
master
Choose a base branch
from
improve_mime_type_deployment
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
f71fa26
Implement MimeInfoEditor
azubieta 36c2c20
MimeInfoEditor::getMimeTypeIconNames
azubieta f985c10
Extract mimetype packages icons
azubieta a07a2eb
Deploy edited mimetype packages
azubieta 6b1fed2
Keep code style
azubieta ccf5a19
Document MimeInfoEditor
azubieta 985c927
Remove unrequired lines
azubieta a417914
Use remote version of appimagetool
azubieta 40a267d
Use system enviroment var ARCH to decide which appimagetool bin shoul…
azubieta 4c30451
Merge branch 'master' into improve_mime_type_deployment
azubieta 5744d24
Update src/libappimage/desktop_integration/integrator/Integrator.cpp
azubieta bb3a0d8
Update src/libappimage/desktop_integration/integrator/Integrator.cpp
azubieta 8d0df13
Update src/libappimage/desktop_integration/integrator/Integrator.cpp
azubieta 6762948
Update src/libappimage/desktop_integration/integrator/Integrator.cpp
azubieta 27113b3
Update src/libappimage/desktop_integration/integrator/Integrator.cpp
azubieta 83932ea
Use stable release of appimagetool
azubieta 7ef3c61
Improve MimeInfoEditor members naming
azubieta 14d7726
Add comments
azubieta File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
97 changes: 97 additions & 0 deletions
97
src/libappimage/desktop_integration/integrator/MimeInfoEditor.cpp
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
// libraries | ||
#include <boost/property_tree/xml_parser.hpp> | ||
#include <boost/algorithm/string.hpp> | ||
#include <iostream> | ||
#include <appimage_handler.h> | ||
|
||
// local | ||
#include "utils/Logger.h" | ||
#include "MimeInfoEditor.h" | ||
|
||
namespace appimage { | ||
namespace desktop_integration { | ||
namespace integrator { | ||
MimeInfoEditor::MimeInfoEditor(std::string data) { | ||
try { | ||
std::stringstream in(data); | ||
using boost::property_tree::ptree; | ||
|
||
// populate tree structure pt | ||
read_xml(in, pt); | ||
} catch (const std::runtime_error& error) { | ||
appimage::utils::Logger::warning(std::string("Unable to read MimeInfo: ") + error.what()); | ||
} | ||
} | ||
|
||
std::string MimeInfoEditor::getResult() { | ||
try { | ||
using boost::property_tree::ptree; | ||
std::stringstream out; | ||
|
||
write_xml(out, pt); | ||
|
||
return out.str(); | ||
} catch (const std::runtime_error& error) { | ||
appimage::utils::Logger::warning(std::string("Unable to edit MimeInfo: ") + error.what()); | ||
return std::string{}; | ||
} | ||
} | ||
|
||
void MimeInfoEditor::prependDeployIdToIcons(const std::string& deployId) { | ||
try { | ||
using boost::property_tree::ptree; | ||
|
||
// traverse pt | ||
for (auto& node: pt.get_child("mime-info")) { | ||
if (node.first == "mime-type") { | ||
auto& subTree = node.second; | ||
// get original icon name from the icon entry | ||
std::string originalName = subTree.get<std::string>("icon.<xmlattr>.name", ""); | ||
|
||
// or fallback to the mime-type name | ||
if (originalName.empty()) { | ||
originalName = subTree.get<std::string>("<xmlattr>.type"); | ||
boost::replace_all(originalName, "/", "-"); | ||
} | ||
|
||
std::string newIconName = deployId + '_' + originalName; | ||
|
||
subTree.put("icon.<xmlattr>.name", newIconName); | ||
} | ||
} | ||
} catch (const std::runtime_error& error) { | ||
appimage::utils::Logger::warning(std::string("Unable to edit MimeInfo: ") + error.what()); | ||
} | ||
} | ||
|
||
std::list<std::string> MimeInfoEditor::getMimeTypeIconNames() const { | ||
std::list<std::string> icons; | ||
|
||
try { | ||
using boost::property_tree::ptree; | ||
|
||
// traverse pt | ||
for (auto& node: pt.get_child("mime-info")) { | ||
if (node.first == "mime-type") { | ||
auto& subTree = node.second; | ||
// get original icon name from the icon entry | ||
std::string iconName = subTree.get<std::string>("icon.<xmlattr>.name", ""); | ||
|
||
// or fallback to the mime-type name | ||
if (iconName.empty()) { | ||
iconName = subTree.get<std::string>("<xmlattr>.type"); | ||
boost::replace_all(iconName, "/", "-"); | ||
} | ||
|
||
icons.push_back(iconName); | ||
} | ||
} | ||
} catch (const std::runtime_error& error) { | ||
appimage::utils::Logger::warning(std::string("Unable to read MimeInfo: ") + error.what()); | ||
} | ||
|
||
return icons; | ||
} | ||
} | ||
} | ||
} |
49 changes: 49 additions & 0 deletions
49
src/libappimage/desktop_integration/integrator/MimeInfoEditor.h
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
#pragma once | ||
|
||
// system | ||
#include <list> | ||
#include <string> | ||
|
||
// libraries | ||
#include <boost/property_tree/ptree.hpp> | ||
|
||
namespace appimage { | ||
namespace desktop_integration { | ||
namespace integrator { | ||
/** | ||
* @brief Edit MimeInfo files to be deployed | ||
*/ | ||
class MimeInfoEditor { | ||
public: | ||
/** | ||
* Create an editor instance to modify the | ||
* @param data | ||
* @param deployId | ||
*/ | ||
MimeInfoEditor(std::string data); | ||
|
||
/** | ||
* @brief Prepends <deployId> to the icon file name | ||
* | ||
* | ||
* @param deployId | ||
*/ | ||
void prependDeployIdToIcons(const std::string& deployId); | ||
|
||
/** | ||
* @return modified MimeInfo | ||
*/ | ||
std::string getResult(); | ||
|
||
/** | ||
* Extract the icon names from from the icon entry or the mime type name | ||
* @return names of the icons related to the mime types | ||
*/ | ||
std::list<std::string> getMimeTypeIconNames() const; | ||
|
||
private: | ||
boost::property_tree::ptree pt; | ||
}; | ||
} | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.