Skip to content

Commit

Permalink
core: default values are now kept in user configuration class ; ui_qt…
Browse files Browse the repository at this point in the history
…: fix default font path
  • Loading branch information
wisk committed Jul 12, 2014
1 parent 2b48804 commit 8fda88c
Show file tree
Hide file tree
Showing 7 changed files with 60 additions and 25 deletions.
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ project(Medusa)
# medusa version
set(VERSION_MAJOR 0)
set(VERSION_MINOR 4)
set(VERSION_PATCH 2)
set(VERSION_PATCH 3)

configure_file(
${CMAKE_SOURCE_DIR}/inc/medusa/version.hpp.in
Expand Down
5 changes: 2 additions & 3 deletions inc/medusa/disassembly_view.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,9 @@ class Medusa_EXPORT Appearance
{
char const* m_pName;
char const* m_pDescription;
char const* m_pDefaultValue;

Information(char const* pName = "", char const* pDescription = "", char const* pDefaultValue = "")
: m_pName(pName), m_pDescription(pDescription), m_pDefaultValue(pDefaultValue) {}
Information(char const* pName = "", char const* pDescription = "")
: m_pName(pName), m_pDescription(pDescription) {}
};

typedef std::map<std::string, Information> MapType;
Expand Down
24 changes: 12 additions & 12 deletions src/core/disassembly_view.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,17 @@ Appearance::MapType& Appearance::GetColors(void)
static MapType s_Colors;
if (s_Colors.empty())
{
s_Colors["color.background_listing"] = Information("Background listing", "", "#1e1e1e");
s_Colors["color.background_address"] = Information("Background address", "", "#626262");
s_Colors["color.instruction_mnemonic"] = Information("Instruction mnemonic", "", "#9a86d6");
s_Colors["color.instruction_register"] = Information("Instruction register", "", "#00aa7f");
s_Colors["color.instruction_immediate"] = Information("Instruction immediate", "", "#ffaa00");
s_Colors["color.comment"] = Information("Comment", "", "#55aa00");
s_Colors["color.selection"] = Information("Selection", "", "#760000");
s_Colors["color.operator"] = Information("Operator", "", "#ff0000");
s_Colors["color.keyword"] = Information("Keyword", "", "#55aaff");
s_Colors["color.label"] = Information("Label", "", "#aaaa7f");
s_Colors["color.string"] = Information("String", "", "#bd72ff");
s_Colors["color.background_listing"] = Information("Background listing", "");
s_Colors["color.background_address"] = Information("Background address", "");
s_Colors["color.instruction_mnemonic"] = Information("Instruction mnemonic", "");
s_Colors["color.instruction_register"] = Information("Instruction register", "");
s_Colors["color.instruction_immediate"] = Information("Instruction immediate", "");
s_Colors["color.comment"] = Information("Comment", "");
s_Colors["color.selection"] = Information("Selection", "");
s_Colors["color.operator"] = Information("Operator", "");
s_Colors["color.keyword"] = Information("Keyword", "");
s_Colors["color.label"] = Information("Label", "");
s_Colors["color.string"] = Information("String", "");
}

return s_Colors;
Expand All @@ -35,7 +35,7 @@ Appearance::MapType& Appearance::GetFonts(void)
static MapType s_Fonts;
if (s_Fonts.empty())
{
s_Fonts["font.listing"] = Information("Listing", "", "DejaVu Sans Mono,10,-1,5,50,0,0,0,0,0");
s_Fonts["font.listing"] = Information("Listing", "");
}

return s_Fonts;
Expand Down
38 changes: 37 additions & 1 deletion src/core/user_configuration.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -99,13 +99,49 @@ bool UserConfiguration::_WriteDefaultOptions(void)
std::lock_guard<MutexType> Lock(m_Mutex);
namespace pt = boost::property_tree;
pt::ptree PropTree;

PropTree.put("core.modules_path", ".");

PropTree.put("color.background_listing", "#1e1e1e");
PropTree.put("color.background_address", "#626262");
PropTree.put("color.instruction_mnemonic", "#9a86d6");
PropTree.put("color.instruction_register", "#00aa7f");
PropTree.put("color.instruction_immediate", "#ffaa00");
PropTree.put("color.comment", "#55aa00");
PropTree.put("color.selection", "#760000");
PropTree.put("color.operator", "#ff0000");
PropTree.put("color.keyword", "#55aaff");
PropTree.put("color.label", "#aaaa7f");
PropTree.put("color.string", "#bd72ff");

PropTree.put("action.add_disassembly_view", "Ctrl+D");
PropTree.put("action.add_semantic_view", "Ctrl+S");
PropTree.put("action.add_control_flow_graph_view", "Ctrl+F");
PropTree.put("action.show_label_dialog", "N");
PropTree.put("action.show_comment_dialog", ";");
PropTree.put("action.change_value_size", "D, V");
PropTree.put("action.to_character", "D, C");
PropTree.put("action.to_reference", "R");
PropTree.put("action.not_value", "~");
PropTree.put("action.negate_value", "-");
PropTree.put("action.reset_value", "Del");
PropTree.put("action.undefine", "U");
PropTree.put("action.to_word", "D, W");
PropTree.put("action.to_dword", "D, D");
PropTree.put("action.to_qword", "D, Q");
PropTree.put("action.analyze", "A");
PropTree.put("action.create_function", "F");
PropTree.put("action.to_utf8_string", "D, S, 1");
PropTree.put("action.to_utf16_name", "D, S, 2");

PropTree.put("font.listing", "DejaVu Sans Mono,10,-1,5,50,0,0,0,0,0");

pt::ini_parser::write_ini(m_CfgPath.string(), PropTree);
return true;
}
catch (std::exception& e)
{
Log::Write("core") << "exception: " << e.what() << LogEnd;
Log::Write("core") << e.what() << LogEnd;
return false;
}
}
Expand Down
1 change: 1 addition & 0 deletions src/ui/qt/DisassemblyView.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ void DisassemblyView::setFont(void)
QFont font;
font.setStyleHint(QFont::Monospace);
font.fromString(fontInfo);

QAbstractScrollArea::setFont(font);

_wChar = fontMetrics().width('M');
Expand Down
12 changes: 5 additions & 7 deletions src/ui/qt/SettingsDialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -96,9 +96,8 @@ SettingsDialog::SettingsDialog(QWidget* pParent, medusa::Medusa& rCore)
QString Value;
std::string Opt;
if (!UserCfg.GetOption(rFontPair.first, Opt))
Value = rFontInfo.m_pDefaultValue;
else
Value = QString::fromStdString(Opt);
continue;
Value = QString::fromStdString(Opt);

AppearanceWidget->setItemWidget(pFontItem, 1, new QFontPicker(this, Value));
}
Expand All @@ -114,9 +113,8 @@ SettingsDialog::SettingsDialog(QWidget* pParent, medusa::Medusa& rCore)
QString Value;
std::string Opt;
if (!UserCfg.GetOption(rColorPair.first, Opt))
Value = rColorInfo.m_pDefaultValue;
else
Value = QString::fromStdString(Opt);
continue;
Value = QString::fromStdString(Opt);

AppearanceWidget->setItemWidget(pColorItem, 1, new QColorPicker(this, Value));
}
Expand Down Expand Up @@ -144,7 +142,7 @@ SettingsDialog::~SettingsDialog()
{
}

void SettingsDialog::SaveSettings()
void SettingsDialog::SaveSettings()
{
medusa::UserConfiguration UserCfg;

Expand Down
3 changes: 2 additions & 1 deletion src/ui/qt/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,8 @@ int main(int argc, char *argv[])
MainWindow window;

a.setWindowIcon(QIcon(":/logo/medusa.png"));
QFontDatabase::addApplicationFont(":/font/DejaVuSansMono.ttf");
if (QFontDatabase::addApplicationFont(":/fonts/DejaVuSansMono.ttf") == -1)
medusa::Log::Write("ui_qt") << "unable to load default font" << medusa::LogEnd;
window.show();
return (a.exec());
}

0 comments on commit 8fda88c

Please sign in to comment.