/src/mpv5/db/objects/FileToContact.java
Java | 178 lines | 105 code | 18 blank | 55 comment | 5 complexity | 6b45edcaf6a0ed8a5a141fd88268cf98 MD5 | raw file
1/* 2 * This file is part of YaBS. 3 * 4 * YaBS is free software: you can redistribute it and/or modify 5 * it under the terms of the GNU General Public License as published by 6 * the Free Software Foundation, either version 3 of the License, or 7 * (at your option) any later version. 8 * 9 * YaBS is distributed in the hope that it will be useful, 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 * GNU General Public License for more details. 13 * 14 * You should have received a copy of the GNU General Public License 15 * along with YaBS. If not, see <http://www.gnu.org/licenses/>. 16 */ 17package mpv5.db.objects; 18 19import java.io.File; 20import javax.swing.Icon; 21import javax.swing.JComponent; 22import javax.swing.JFileChooser; 23import mpv5.db.common.Context; 24import mpv5.db.common.DatabaseObject; 25import mpv5.db.common.QueryHandler; 26import mpv5.logging.Log; 27import mpv5.utils.files.FileDirectoryHandler; 28import mpv5.utils.images.MPIcon; 29 30/** 31 * 32 * 33 */ 34public class FileToContact extends DatabaseObject { 35 36 private String description = ""; 37 private int contactsids; 38 private String filename = ""; 39 private File file; 40 private int intsize; 41 private String mimetype; 42 43 public FileToContact() { 44 setContext(Context.getFilesToContacts()); 45 } 46 47 @Override 48 public JComponent getView() { 49 try { 50 FileDirectoryHandler.open(getFile()); 51 } catch (Exception e) { 52 Log.Debug(e); 53 } 54 return null; 55 } 56 57 /** 58 * @return the description 59 */ 60 public String __getDescription() { 61 return description; 62 } 63 64 /** 65 * @param description the description to set 66 */ 67 public void setDescription(String description) { 68 this.description = description; 69 } 70 71 /** 72 * @return the contactsids 73 */ 74 public int __getContactsids() { 75 return contactsids; 76 } 77 78 /** 79 * @param contactsids the contactsids to set 80 */ 81 public void setContactsids(int contactsids) { 82 this.contactsids = contactsids; 83 } 84 85 /** 86 * @return the filename 87 */ 88 public String __getFilename() { 89 return filename; 90 } 91 92 /** 93 * @param filename the filename to set 94 */ 95 public void setFilename(String filename) { 96 this.filename = filename; 97 } 98 MPIcon icon; 99 100 @Override 101 public mpv5.utils.images.MPIcon getIcon() { 102 if (icon == null) { 103 try { 104 Log.Debug(this, "Determining Icon for " + __getCname()); 105 icon = new MPIcon(MPIcon.DIRECTORY_DEFAULT_ICONS + __getCname().substring(__getCname().lastIndexOf(".") + 1, __getCname().length()) + ".png"); 106 return icon; 107 } catch (Exception e) { 108 Log.Debug(this, "Icon file not existing in " + MPIcon.DIRECTORY_DEFAULT_ICONS); 109 try { 110 JFileChooser chooser = new JFileChooser(); 111 icon = new MPIcon(chooser.getIcon(new File(filename))); 112 return icon; 113 } catch (Exception ez) { 114 Log.Debug(this, ez); 115 icon = new MPIcon(MPIcon.DIRECTORY_DEFAULT_ICONS + "folder_tar.png"); 116 return icon; 117 } 118 } 119 } else { 120 return icon; 121 } 122 } 123 124 /** 125 * Fetches the physical file from db 126 * 127 * @return 128 */ 129 public synchronized File getFile() { 130 if (file == null) { 131 try { 132 file = QueryHandler.instanceOf().clone(Context.getFiles()).retrieveFile(filename, 133 new File(FileDirectoryHandler.getTempDir() + getCname())); 134 } catch (Exception e) { 135 Log.Debug(e); 136 } 137 } 138 return file; 139 } 140 141 /** 142 * @return the mimetype 143 */ 144 public String __getMimetype() { 145 return mimetype; 146 } 147 148 /** 149 * @param mimetype the mimetype to set 150 */ 151 public void setMimetype(String mimetype) { 152 this.mimetype = mimetype; 153 } 154 155 /** 156 * @return the intsize 157 */ 158 public int __getIntsize() { 159 return intsize; 160 } 161 162 /** 163 * @param intsize the intsize to set 164 */ 165 public void setIntsize(int intsize) { 166 this.intsize = intsize; 167 } 168 169 @Override 170 public boolean delete() { 171 try { 172 QueryHandler.instanceOf().clone(Context.getFiles()).removeFile(filename); 173 } catch (Exception ex) { 174 Log.Debug(ex); 175 } 176 return super.delete(); 177 } 178}