/src/mpv5/db/objects/FileToContact.java
Java | 178 lines | 105 code | 18 blank | 55 comment | 5 complexity | 6b45edcaf6a0ed8a5a141fd88268cf98 MD5 | raw file
Possible License(s): LGPL-3.0, Apache-2.0, GPL-3.0, GPL-2.0, AGPL-3.0, JSON, BSD-3-Clause
- /*
- * This file is part of YaBS.
- *
- * YaBS is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * YaBS is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with YaBS. If not, see <http://www.gnu.org/licenses/>.
- */
- package mpv5.db.objects;
- import java.io.File;
- import javax.swing.Icon;
- import javax.swing.JComponent;
- import javax.swing.JFileChooser;
- import mpv5.db.common.Context;
- import mpv5.db.common.DatabaseObject;
- import mpv5.db.common.QueryHandler;
- import mpv5.logging.Log;
- import mpv5.utils.files.FileDirectoryHandler;
- import mpv5.utils.images.MPIcon;
- /**
- *
- *
- */
- public class FileToContact extends DatabaseObject {
- private String description = "";
- private int contactsids;
- private String filename = "";
- private File file;
- private int intsize;
- private String mimetype;
- public FileToContact() {
- setContext(Context.getFilesToContacts());
- }
- @Override
- public JComponent getView() {
- try {
- FileDirectoryHandler.open(getFile());
- } catch (Exception e) {
- Log.Debug(e);
- }
- return null;
- }
- /**
- * @return the description
- */
- public String __getDescription() {
- return description;
- }
- /**
- * @param description the description to set
- */
- public void setDescription(String description) {
- this.description = description;
- }
- /**
- * @return the contactsids
- */
- public int __getContactsids() {
- return contactsids;
- }
- /**
- * @param contactsids the contactsids to set
- */
- public void setContactsids(int contactsids) {
- this.contactsids = contactsids;
- }
- /**
- * @return the filename
- */
- public String __getFilename() {
- return filename;
- }
- /**
- * @param filename the filename to set
- */
- public void setFilename(String filename) {
- this.filename = filename;
- }
- MPIcon icon;
- @Override
- public mpv5.utils.images.MPIcon getIcon() {
- if (icon == null) {
- try {
- Log.Debug(this, "Determining Icon for " + __getCname());
- icon = new MPIcon(MPIcon.DIRECTORY_DEFAULT_ICONS + __getCname().substring(__getCname().lastIndexOf(".") + 1, __getCname().length()) + ".png");
- return icon;
- } catch (Exception e) {
- Log.Debug(this, "Icon file not existing in " + MPIcon.DIRECTORY_DEFAULT_ICONS);
- try {
- JFileChooser chooser = new JFileChooser();
- icon = new MPIcon(chooser.getIcon(new File(filename)));
- return icon;
- } catch (Exception ez) {
- Log.Debug(this, ez);
- icon = new MPIcon(MPIcon.DIRECTORY_DEFAULT_ICONS + "folder_tar.png");
- return icon;
- }
- }
- } else {
- return icon;
- }
- }
- /**
- * Fetches the physical file from db
- *
- * @return
- */
- public synchronized File getFile() {
- if (file == null) {
- try {
- file = QueryHandler.instanceOf().clone(Context.getFiles()).retrieveFile(filename,
- new File(FileDirectoryHandler.getTempDir() + getCname()));
- } catch (Exception e) {
- Log.Debug(e);
- }
- }
- return file;
- }
- /**
- * @return the mimetype
- */
- public String __getMimetype() {
- return mimetype;
- }
- /**
- * @param mimetype the mimetype to set
- */
- public void setMimetype(String mimetype) {
- this.mimetype = mimetype;
- }
- /**
- * @return the intsize
- */
- public int __getIntsize() {
- return intsize;
- }
- /**
- * @param intsize the intsize to set
- */
- public void setIntsize(int intsize) {
- this.intsize = intsize;
- }
- @Override
- public boolean delete() {
- try {
- QueryHandler.instanceOf().clone(Context.getFiles()).removeFile(filename);
- } catch (Exception ex) {
- Log.Debug(ex);
- }
- return super.delete();
- }
- }