File indexing completed on 2024-04-21 15:55:47
0001 /*************************************************************************** 0002 Copyright (C) 2012 by Michel Ludwig (michel.ludwig@kdemail.net) 0003 ***************************************************************************/ 0004 0005 /*************************************************************************** 0006 * * 0007 * This program is free software; you can redistribute it and/or modify * 0008 * it under the terms of the GNU General Public License as published by * 0009 * the Free Software Foundation; either version 2 of the License, or * 0010 * (at your option) any later version. * 0011 * * 0012 ***************************************************************************/ 0013 0014 #include "tool_utils.h" 0015 0016 #include <KLocalizedString> 0017 0018 namespace KileTool { 0019 0020 ToolConfigPair::ToolConfigPair() 0021 : QPair<QString, QString>() 0022 { 0023 } 0024 0025 ToolConfigPair::ToolConfigPair(const QString& toolName, const QString& configName) 0026 : QPair<QString, QString>(toolName, configName) 0027 { 0028 } 0029 0030 bool ToolConfigPair::operator<(const ToolConfigPair& p2) const 0031 { 0032 const int firstCompare = first.localeAwareCompare(p2.first); 0033 0034 if(firstCompare != 0) { 0035 return (firstCompare < 0); 0036 } 0037 0038 if(second.isEmpty() || second == DEFAULT_TOOL_CONFIGURATION) { 0039 if(p2.second.isEmpty() || p2.second == DEFAULT_TOOL_CONFIGURATION) { 0040 return false; 0041 } 0042 else { 0043 return true; 0044 } 0045 } 0046 if(p2.second.isEmpty() || p2.second == DEFAULT_TOOL_CONFIGURATION) { 0047 if(second.isEmpty() || second == DEFAULT_TOOL_CONFIGURATION) { 0048 return true; 0049 } 0050 else { 0051 return false; 0052 } 0053 } 0054 0055 return (second.localeAwareCompare(p2.second) < 0); 0056 } 0057 0058 QString ToolConfigPair::userStringRepresentation(const QString& toolName, const QString& toolConfig) 0059 { 0060 return (toolConfig == DEFAULT_TOOL_CONFIGURATION) 0061 ? toolName : i18nc("<tool name> - <configuration>", "%1 - %2", toolName, toolConfig); 0062 } 0063 0064 QString ToolConfigPair::configStringRepresentation(const QString& toolName, const QString& toolConfig) 0065 { 0066 QString configString = toolConfig; 0067 if(configString == DEFAULT_TOOL_CONFIGURATION) { 0068 configString.clear(); 0069 } 0070 if(toolName.isEmpty() && configString.isEmpty()) { 0071 return ""; 0072 } 0073 if(configString.isEmpty()) { 0074 return toolName; 0075 } 0076 return toolName + '/' + configString; 0077 } 0078 0079 ToolConfigPair ToolConfigPair::fromConfigStringRepresentation(const QString& s) 0080 { 0081 const int separatorIndex = s.indexOf('/'); 0082 if(separatorIndex < 0) { // for example, is 's' is empty 0083 return ToolConfigPair(s, DEFAULT_TOOL_CONFIGURATION); 0084 } 0085 QString configString = s.mid(separatorIndex + 1); 0086 if(configString.isEmpty()) { 0087 configString = DEFAULT_TOOL_CONFIGURATION; 0088 } 0089 return ToolConfigPair(s.left(separatorIndex), configString); 0090 } 0091 0092 }