Ticket #13952: 0001-Icon-O-Matic-convert-IOM-to-HVIF-RDef-Source-SVG-fro.patch
File 0001-Icon-O-Matic-convert-IOM-to-HVIF-RDef-Source-SVG-fro.patch, 5.3 KB (added by , 7 years ago) |
---|
-
src/apps/icon-o-matic/IconEditorApp.cpp
From 0908b06f1c0c041da500bf2e413b55bf8ae45644 Mon Sep 17 00:00:00 2001 From: Owen <owenca@users.noreply.github.com> Date: Thu, 11 Jan 2018 16:55:29 +0000 Subject: [PATCH] Icon-O-Matic: convert IOM to HVIF/RDef/Source/SVG from command line Usage: Icon-O-Matic -[H|R|S|s] -o output_file IOM_file Returns: 0 if successful; nonzero otherwise Fixes #13952 --- src/apps/icon-o-matic/IconEditorApp.cpp | 128 ++++++++++++++++++++++++++++++-- src/apps/icon-o-matic/IconEditorApp.h | 2 + src/apps/icon-o-matic/main.cpp | 4 +- 3 files changed, 125 insertions(+), 9 deletions(-) diff --git a/src/apps/icon-o-matic/IconEditorApp.cpp b/src/apps/icon-o-matic/IconEditorApp.cpp index d667ce9..96f7483 100644
a b 6 6 7 7 #include "IconEditorApp.h" 8 8 9 #include "Document.h" 10 #include "FlatIconExporter.h" 11 #include "Icon.h" 12 #include "MessageImporter.h" 13 #include "RDefExporter.h" 14 #include "SimpleFileSaver.h" 15 #include "SourceExporter.h" 16 #include "SVGExporter.h" 17 9 18 #include <new> 10 19 #include <stdio.h> 11 20 #include <string.h> … … 32 41 #define B_TRANSLATION_CONTEXT "Icon-O-Matic-Main" 33 42 34 43 44 extern int exitCode; 45 46 35 47 using std::nothrow; 36 48 37 49 static const char* kAppSig = "application/x-vnd.haiku-icon_o_matic"; 38 50 39 51 static const float kWindowOffset = 20; 40 52 53 static bool isCLI; 54 41 55 42 56 IconEditorApp::IconEditorApp() 43 57 : 44 BApplication(kAppSig) ,45 fWindowCount(0), 46 fLastWindowFrame(50, 50, 900, 750), 58 BApplication(kAppSig) 59 { 60 } 47 61 48 fOpenPanel(NULL),49 fSavePanel(NULL),50 62 51 fLastOpenPath(""), 52 fLastSavePath(""), 53 fLastExportPath("") 63 void 64 IconEditorApp::_Init() 54 65 { 66 fWindowCount = 0; 67 fLastWindowFrame.Set(50, 50, 900, 750); 68 69 fOpenPanel = NULL; 70 fSavePanel = NULL; 71 72 fLastOpenPath = ""; 73 fLastSavePath = ""; 74 fLastExportPath = ""; 75 55 76 // create file panels 56 77 BMessenger messenger(this, this); 57 78 BMessage message(B_REFS_RECEIVED); … … IconEditorApp::~IconEditorApp() 79 100 bool 80 101 IconEditorApp::QuitRequested() 81 102 { 103 if (isCLI) 104 return true; 105 82 106 // Run the QuitRequested() hook in each window's own thread. Otherwise 83 107 // the BAlert which a window shows when an icon is not saved will not 84 108 // repaint the window. (BAlerts check which thread is running Go() and … … IconEditorApp::MessageReceived(BMessage* message) 202 226 void 203 227 IconEditorApp::ReadyToRun() 204 228 { 229 if (isCLI) 230 return; 231 232 _Init(); 233 205 234 // create main window 206 235 if (fWindowCount == 0) 207 236 _NewWindow()->Show(); … … IconEditorApp::RefsReceived(BMessage* message) 248 277 } 249 278 250 279 280 static status_t 281 ConvertIcon(const char* from, const char* to, const char* format) 282 { 283 uint32 exportMode; 284 if (strcmp(format, "-H") == 0) 285 exportMode = EXPORT_MODE_FLAT_ICON; 286 else if (strcmp(format, "-R") == 0) 287 exportMode = EXPORT_MODE_ICON_RDEF; 288 else if (strcmp(format, "-S") == 0) 289 exportMode = EXPORT_MODE_ICON_SOURCE; 290 else if (strcmp(format, "-s") == 0) 291 exportMode = EXPORT_MODE_SVG; 292 else 293 return B_ERROR; 294 295 entry_ref ref; 296 status_t ret = get_ref_for_path(from, &ref); 297 if (ret != B_OK) 298 return ret; 299 300 BFile file(&ref, B_READ_ONLY); 301 ret = file.InitCheck(); 302 if (ret < B_OK) 303 return ret; 304 305 ret = get_ref_for_path(to, &ref); 306 if (ret != B_OK) 307 return ret; 308 309 Icon* icon = new (nothrow) Icon(); 310 if (icon == NULL) 311 return B_ERROR; 312 313 MessageImporter msgImporter; 314 ret = msgImporter.Import(icon, &file); 315 if (ret < B_OK) { 316 delete icon; 317 return ret; 318 } 319 320 DocumentSaver* saver = NULL; 321 switch (exportMode) { 322 case EXPORT_MODE_FLAT_ICON: 323 saver = new SimpleFileSaver(new FlatIconExporter(), ref); 324 break; 325 case EXPORT_MODE_ICON_RDEF: 326 saver = new SimpleFileSaver(new RDefExporter(), ref); 327 break; 328 case EXPORT_MODE_ICON_SOURCE: 329 saver = new SimpleFileSaver(new SourceExporter(), ref); 330 break; 331 case EXPORT_MODE_SVG: 332 saver = new SimpleFileSaver(new SVGExporter(), ref); 333 break; 334 } 335 336 if (saver == NULL) { 337 delete icon; 338 return B_ERROR; 339 } 340 341 Document* document = new Document(to); 342 if (document == NULL) { 343 delete icon; 344 return B_ERROR; 345 } 346 347 document->SetIcon(icon); 348 document->SetExportSaver(saver); 349 saver->Save(document); 350 351 return B_OK; 352 } 353 354 251 355 void 252 356 IconEditorApp::ArgvReceived(int32 argc, char** argv) 253 357 { 254 358 if (argc < 2) 255 359 return; 256 360 361 // Usage: Icon-O-Matic -[H|R|S|s] -o output_file IOM_file 362 if (argc == 5 && strcmp(argv[2], "-o") == 0) { 363 isCLI = true; 364 exitCode = ConvertIcon(argv[4], argv[3], argv[1]); 365 PostMessage(B_QUIT_REQUESTED); 366 return; 367 } 368 257 369 entry_ref ref; 258 370 259 371 for (int32 i = 1; i < argc; i++) { -
src/apps/icon-o-matic/IconEditorApp.h
diff --git a/src/apps/icon-o-matic/IconEditorApp.h b/src/apps/icon-o-matic/IconEditorApp.h index 44df93a..f6ecc88 100644
a b public: 60 60 // IconEditorApp 61 61 62 62 private: 63 void _Init(); 64 63 65 MainWindow* _NewWindow(); 64 66 65 67 void _SyncPanels(BFilePanel* from, -
src/apps/icon-o-matic/main.cpp
diff --git a/src/apps/icon-o-matic/main.cpp b/src/apps/icon-o-matic/main.cpp index c7b6492..0f997b3 100644
a b 8 8 9 9 #include "IconEditorApp.h" 10 10 11 int exitCode; 12 11 13 int 12 14 main(int argc, char** argv) 13 15 { … … main(int argc, char** argv) 16 18 17 19 delete app; 18 20 19 return 0;21 return exitCode; 20 22 }