Ticket #13952: 0001-Icon-O-Matic-convert-IOM-to-HVIF-RDef-SVG-source-fro.patch
File 0001-Icon-O-Matic-convert-IOM-to-HVIF-RDef-SVG-source-fro.patch, 5.6 KB (added by , 7 years ago) |
---|
-
src/apps/icon-o-matic/IconEditorApp.cpp
From 626c454f4d1142310a0f1e1722a319705fe67337 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/SVG/source from command line It returns 0 if successful or nonzero otherwise. Fixes #13952 --- src/apps/icon-o-matic/IconEditorApp.cpp | 150 ++++++++++++++++++++++++++++++-- src/apps/icon-o-matic/IconEditorApp.h | 2 + src/apps/icon-o-matic/main.cpp | 4 +- 3 files changed, 147 insertions(+), 9 deletions(-) diff --git a/src/apps/icon-o-matic/IconEditorApp.cpp b/src/apps/icon-o-matic/IconEditorApp.cpp index d667ce9..bd29b1e 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 void 281 Help() 282 { 283 puts("Usage: Icon-O-Matic OPTION -o OUTPUT_FILE IOM_FILE"); 284 puts(" -H convert to HVIF"); 285 puts(" -R convert to RDef"); 286 puts(" -S convert to SVG"); 287 puts(" -s convert to source"); 288 puts(" -h, --help"); 289 puts(" display this help"); 290 } 291 292 293 static status_t 294 ConvertIcon(const char* from, const char* to, const char* format) 295 { 296 uint32 exportMode; 297 if (strcmp(format, "-H") == 0) 298 exportMode = EXPORT_MODE_FLAT_ICON; 299 else if (strcmp(format, "-R") == 0) 300 exportMode = EXPORT_MODE_ICON_RDEF; 301 else if (strcmp(format, "-S") == 0) 302 exportMode = EXPORT_MODE_SVG; 303 else if (strcmp(format, "-s") == 0) 304 exportMode = EXPORT_MODE_ICON_SOURCE; 305 else { 306 Help(); 307 return B_ERROR; 308 } 309 310 entry_ref ref; 311 status_t ret = get_ref_for_path(from, &ref); 312 if (ret != B_OK) 313 return ret; 314 315 BFile file(&ref, B_READ_ONLY); 316 ret = file.InitCheck(); 317 if (ret < B_OK) 318 return ret; 319 320 ret = get_ref_for_path(to, &ref); 321 if (ret != B_OK) 322 return ret; 323 324 Icon* icon = new (nothrow) Icon(); 325 if (icon == NULL) 326 return B_ERROR; 327 328 MessageImporter msgImporter; 329 ret = msgImporter.Import(icon, &file); 330 if (ret < B_OK) { 331 delete icon; 332 return ret; 333 } 334 335 DocumentSaver* saver = NULL; 336 switch (exportMode) { 337 case EXPORT_MODE_FLAT_ICON: 338 saver = new SimpleFileSaver(new FlatIconExporter(), ref); 339 break; 340 case EXPORT_MODE_ICON_RDEF: 341 saver = new SimpleFileSaver(new RDefExporter(), ref); 342 break; 343 case EXPORT_MODE_ICON_SOURCE: 344 saver = new SimpleFileSaver(new SourceExporter(), ref); 345 break; 346 case EXPORT_MODE_SVG: 347 saver = new SimpleFileSaver(new SVGExporter(), ref); 348 break; 349 } 350 351 if (saver == NULL) { 352 delete icon; 353 return B_ERROR; 354 } 355 356 Document* document = new Document(to); 357 if (document == NULL) { 358 delete icon; 359 return B_ERROR; 360 } 361 362 document->SetIcon(icon); 363 document->SetExportSaver(saver); 364 saver->Save(document); 365 366 return B_OK; 367 } 368 369 251 370 void 252 371 IconEditorApp::ArgvReceived(int32 argc, char** argv) 253 372 { 254 373 if (argc < 2) 255 374 return; 256 375 376 if (*argv[1] == '-') { 377 if ((strcmp(argv[1], "-h") == 0 || strcmp(argv[1], "--help") == 0)) 378 Help(); 379 else if (argc == 5 && strcmp(argv[2], "-o") == 0) 380 exitCode = ConvertIcon(argv[4], argv[3], argv[1]); 381 else { 382 Help(); 383 exitCode = B_ERROR; 384 } 385 386 isCLI = true; 387 PostMessage(B_QUIT_REQUESTED); 388 return; 389 } 390 257 391 entry_ref ref; 258 392 259 393 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 }