1 /* 2 * Copyright 2013-2024, Haiku, Inc. All Rights Reserved. 3 * Distributed under the terms of the MIT License. 4 * 5 * Authors: 6 * Ingo Weinhold <ingo_weinhold@gmx.de> 7 * Stephan Aßmus <superstippi@gmx.de> 8 * Rene Gollent <rene@gollent.com> 9 * Julian Harnath <julian.harnath@rwth-aachen.de> 10 * Andrew Lindesay <apl@lindesay.co.nz> 11 * 12 * Note that this file has been re-factored from `PackageManager.cpp` and 13 * authors have been carried across in 2021. 14 */ 15 16 17 #include "DeskbarLink.h" 18 19 #include "Logger.h" 20 21 22 #define kPathKey "path" 23 #define kLinkKey "link" 24 25 26 DeskbarLink::DeskbarLink() 27 { 28 } 29 30 31 DeskbarLink::DeskbarLink(const BString& path, const BString& link) 32 : 33 fPath(path), 34 fLink(link) 35 { 36 } 37 38 39 DeskbarLink::DeskbarLink(const DeskbarLink& other) 40 : 41 fPath(other.fPath), 42 fLink(other.fLink) 43 { 44 } 45 46 47 DeskbarLink::DeskbarLink(BMessage* from) 48 { 49 if (from->FindString(kPathKey, &fPath) != B_OK) { 50 HDERROR("expected key [%s] in the message data when creating a " 51 "captcha", kPathKey); 52 } 53 54 if (from->FindString(kLinkKey, &fLink) != B_OK) { 55 HDERROR("expected key [%s] in the message data when creating a " 56 "captcha", kLinkKey); 57 } 58 } 59 60 61 62 DeskbarLink::~DeskbarLink() 63 { 64 } 65 66 67 const BString 68 DeskbarLink::Path() const 69 { 70 return fPath; 71 } 72 73 74 const BString 75 DeskbarLink::Link() const 76 { 77 return fLink; 78 } 79 80 81 const BString 82 DeskbarLink::Title() const 83 { 84 BString result = "???"; 85 86 if (!fLink.IsEmpty()) { 87 int32 lastSlash = fLink.FindLast('/'); 88 89 if (lastSlash != B_ERROR) 90 fLink.CopyInto(result, lastSlash + 1, (fLink.Length() - lastSlash) - 1); 91 else 92 result = fLink; 93 } 94 95 return result; 96 } 97 98 99 status_t 100 DeskbarLink::Archive(BMessage* into, bool deep) const 101 { 102 status_t result = B_OK; 103 if (result == B_OK && into == NULL) 104 result = B_ERROR; 105 if (result == B_OK) 106 result = into->AddString(kPathKey, fPath); 107 if (result == B_OK) 108 result = into->AddString(kLinkKey, fLink); 109 return result; 110 } 111 112 113 DeskbarLink& 114 DeskbarLink::operator=(const DeskbarLink& other) 115 { 116 if (this == &other) 117 return *this; 118 fPath = other.Path(); 119 fLink = other.Link(); 120 return *this; 121 } 122 123 124 bool 125 DeskbarLink::operator==(const DeskbarLink& other) 126 { 127 return fPath == other.fPath && fLink == other.fLink; 128 } 129 130 131 bool 132 DeskbarLink::operator!=(const DeskbarLink& other) 133 { 134 return !(*this == other); 135 } 136