You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
280 lines
7.2 KiB
280 lines
7.2 KiB
15 years ago
|
/*
|
||
13 years ago
|
TDE Icon Editor - a small graphics drawing program for the TDE
|
||
15 years ago
|
Copyright (C) 1998 Thomas Tanghus (tanghus@kde.org)
|
||
|
|
||
|
This program 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 2 of the License, or (at your option) any later version.
|
||
|
|
||
|
This program 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 Library General Public License
|
||
|
along with this library; see the file COPYING.LIB. If not, write to
|
||
|
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
|
||
|
Boston, MA 02110-1301, USA.
|
||
|
*/
|
||
|
|
||
|
#include <stdlib.h>
|
||
|
|
||
14 years ago
|
#include <tqimage.h>
|
||
15 years ago
|
|
||
12 years ago
|
#include <tdemessagebox.h>
|
||
12 years ago
|
#include <tdefiledialog.h>
|
||
|
#include <tdeio/netaccess.h>
|
||
15 years ago
|
#include <kimageio.h>
|
||
|
#include <kdebug.h>
|
||
12 years ago
|
#include <tdelocale.h>
|
||
15 years ago
|
|
||
11 years ago
|
#include "tdeicon.h"
|
||
15 years ago
|
#include "utils.h"
|
||
|
|
||
12 years ago
|
TDEIconEditIcon::TDEIconEditIcon(TQObject *parent, const TQImage *img, KURL url)
|
||
13 years ago
|
: TQObject(parent)
|
||
15 years ago
|
{
|
||
|
f = 0;
|
||
|
_lastdir = "/";
|
||
|
//checkUnNamedBackup(img);
|
||
|
|
||
|
if(!url.isEmpty())
|
||
|
{
|
||
|
open(img, url);
|
||
|
}
|
||
|
}
|
||
|
|
||
|
|
||
12 years ago
|
TDEIconEditIcon::~TDEIconEditIcon()
|
||
15 years ago
|
{
|
||
|
}
|
||
|
|
||
|
|
||
12 years ago
|
bool TDEIconEditIcon::open(const TQImage *image, KURL url)
|
||
15 years ago
|
{
|
||
14 years ago
|
TQImage *img = (TQImage*)image;
|
||
15 years ago
|
|
||
|
if(url.isEmpty())
|
||
|
return false;
|
||
|
|
||
12 years ago
|
kdDebug(4640) << "TDEIconEditIcon::open " << url.prettyURL() << endl;
|
||
15 years ago
|
|
||
|
if(!url.isValid()) // try to see if it is a relative filename
|
||
|
{
|
||
12 years ago
|
kdDebug(4640) << "TDEIconEditIcon::open (malformed) " << url.prettyURL() << endl;
|
||
15 years ago
|
|
||
14 years ago
|
TQFileInfo fi(url.url());
|
||
15 years ago
|
if(fi.isRelative())
|
||
|
url = "file:" + fi.absFilePath();
|
||
|
|
||
|
if(!url.isValid()) // Giving up
|
||
|
{
|
||
13 years ago
|
TQString msg = i18n("The URL: %1 \nseems to be malformed.\n").arg(url.url());
|
||
13 years ago
|
KMessageBox::sorry((TQWidget*)parent(), msg);
|
||
15 years ago
|
return false;
|
||
|
}
|
||
|
}
|
||
|
|
||
14 years ago
|
TQString filename;
|
||
15 years ago
|
|
||
|
if(url.isLocalFile())
|
||
|
{
|
||
|
filename = url.path();
|
||
|
}
|
||
|
else
|
||
|
{
|
||
12 years ago
|
if(!TDEIO::NetAccess::download( url, filename, (TQWidget*)parent() ))
|
||
15 years ago
|
{
|
||
13 years ago
|
TQString msg = i18n("There was an error loading:\n%1\n").arg(url.prettyURL());
|
||
13 years ago
|
KMessageBox::error((TQWidget*)parent(), msg);
|
||
15 years ago
|
return false;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
bool loadedOk = img->load(filename);
|
||
|
|
||
|
if(!url.isLocalFile())
|
||
|
{
|
||
12 years ago
|
TDEIO::NetAccess::removeTempFile( filename );
|
||
15 years ago
|
}
|
||
|
|
||
|
if(!loadedOk)
|
||
|
{
|
||
13 years ago
|
TQString msg = i18n("There was an error loading:\n%1\n").arg(url.prettyURL());
|
||
13 years ago
|
KMessageBox::error((TQWidget*)parent(), msg);
|
||
15 years ago
|
}
|
||
|
else
|
||
|
{
|
||
12 years ago
|
kdDebug(4640) << "TDEIconEditIcon::open - Image loaded" << endl;
|
||
15 years ago
|
|
||
|
// _url is saved off for use in saving the image to the same
|
||
|
// file later - should include full path
|
||
|
if(url.isLocalFile())
|
||
|
{
|
||
|
_url = url.path();
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
_url = "";
|
||
|
}
|
||
|
|
||
12 years ago
|
kdDebug(4640) << "TDEIcon: _url: " << _url << endl;
|
||
15 years ago
|
|
||
|
// this causes updates of preview, color palettes, etc.
|
||
|
emit loaded(img);
|
||
|
kdDebug(4640) << "loaded(img)" << endl;
|
||
|
|
||
|
// this is the name that shows up in status bar -
|
||
|
// should be filename with path
|
||
|
emit newname(url.prettyURL());
|
||
|
kdDebug(4640) << "newname(_url) : " << url.prettyURL() << endl;
|
||
|
|
||
|
emit addrecent(url.prettyURL());
|
||
|
|
||
12 years ago
|
kdDebug(4640) << "TDEIconEditIcon::open - done" << endl;
|
||
15 years ago
|
}
|
||
|
|
||
|
return loadedOk;
|
||
|
}
|
||
|
|
||
|
|
||
|
|
||
12 years ago
|
bool TDEIconEditIcon::promptForFile(const TQImage *img)
|
||
15 years ago
|
{
|
||
12 years ago
|
kdDebug(4640) << "TDEIconEditIcon::promptForFile(const TQImage *img)" << endl;
|
||
15 years ago
|
/*
|
||
14 years ago
|
TQString filter = i18n("*|All Files (*)\n"
|
||
15 years ago
|
"*.xpm|XPM (*.xpm)\n"
|
||
|
"*.png|PNG (*.png)\n"
|
||
|
"*.gif|GIF files (*.gif)\n"
|
||
|
"*.jpg|JPEG files (*.jpg)\n"
|
||
|
"*.ico|Icon files (*.ico)\n");
|
||
|
|
||
|
|
||
14 years ago
|
KURL url = KFileDialog::getOpenURL( TQString(), filter );
|
||
15 years ago
|
*/
|
||
|
bool loaded = false;
|
||
13 years ago
|
KURL url = KFileDialog::getImageOpenURL( TQString(), TQT_TQWIDGET(parent()) );
|
||
15 years ago
|
|
||
|
if( !url.isEmpty() )
|
||
|
{
|
||
|
loaded = open( img, url );
|
||
|
}
|
||
|
|
||
|
return loaded;
|
||
|
}
|
||
|
|
||
|
|
||
|
|
||
12 years ago
|
bool TDEIconEditIcon::saveAs(const TQImage *image)
|
||
15 years ago
|
{
|
||
12 years ago
|
kdDebug(4640) << "TDEIconEditIcon::saveAs" << endl;
|
||
15 years ago
|
|
||
14 years ago
|
TQString file;
|
||
15 years ago
|
|
||
|
//Get list of file types..
|
||
13 years ago
|
KFileDialog *dialog=new KFileDialog(TQString(), TQString(), TQT_TQWIDGET(parent()), "file dialog", true);
|
||
15 years ago
|
dialog->setCaption( i18n("Save Icon As") );
|
||
|
dialog->setKeepLocation( true );
|
||
|
dialog->setMimeFilter( KImageIO::mimeTypes(KImageIO::Writing), "image/png" );
|
||
|
dialog->setOperationMode( KFileDialog::Saving );
|
||
|
|
||
14 years ago
|
if(dialog->exec()==TQDialog::Accepted)
|
||
15 years ago
|
{
|
||
|
file = dialog->selectedFile();
|
||
|
if( file.isNull() )
|
||
|
{
|
||
|
delete dialog;
|
||
|
return false;
|
||
|
}
|
||
|
if ( !KImageIO::canWrite(KImageIO::type(file)) )
|
||
|
{
|
||
|
if ( KImageIO::canWrite(KImageIO::typeForMime(dialog->currentFilter())) )
|
||
|
file += "."+KImageIO::suffix(KImageIO::typeForMime(dialog->currentFilter()));
|
||
|
else
|
||
|
file += ".png";
|
||
|
}
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
delete dialog;
|
||
|
return false;
|
||
|
}
|
||
|
|
||
|
delete dialog;
|
||
|
|
||
14 years ago
|
if(TQFile::exists(file))
|
||
15 years ago
|
{
|
||
13 years ago
|
int r=KMessageBox::warningContinueCancel(TQT_TQWIDGET(parent()),
|
||
15 years ago
|
i18n( "A file named \"%1\" already exists. "
|
||
13 years ago
|
"Overwrite it?" ).arg(file),
|
||
15 years ago
|
i18n( "Overwrite File?" ),
|
||
|
i18n( "&Overwrite" ) );
|
||
|
|
||
|
if(r==KMessageBox::Cancel)
|
||
|
{
|
||
|
return false;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
return save( image, file );
|
||
|
}
|
||
|
|
||
|
|
||
|
|
||
12 years ago
|
bool TDEIconEditIcon::save(const TQImage *image, const TQString &_filename)
|
||
15 years ago
|
{
|
||
12 years ago
|
kdDebug(4640) << "TDEIconEditIcon::save" << endl;
|
||
14 years ago
|
TQString filename = _filename;
|
||
15 years ago
|
|
||
|
if(filename.isEmpty())
|
||
|
{
|
||
|
if(_url.isEmpty())
|
||
|
{
|
||
|
return saveAs(image);
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
KURL turl(_url);
|
||
|
filename = turl.path();
|
||
|
}
|
||
|
}
|
||
|
|
||
14 years ago
|
TQImage *img = (TQImage*)image;
|
||
15 years ago
|
img->setAlphaBuffer(true);
|
||
|
|
||
|
KURL turl(filename);
|
||
14 years ago
|
TQString str = turl.path();
|
||
15 years ago
|
bool savedOk = false;
|
||
|
|
||
|
/* base image type on file extension - let kimageio
|
||
|
take care of this determination */
|
||
|
|
||
|
if(img->save(str, KImageIO::type(str).ascii()))
|
||
|
{
|
||
|
kdDebug(4640) << "img->save()) successful" << endl;
|
||
|
emit saved();
|
||
|
_url = filename;
|
||
|
|
||
|
// emit signal to change title bar to reflect new name
|
||
|
emit newname(filename);
|
||
|
kdDebug(4640) << "newname(filenamme) : " << _url << endl;
|
||
|
savedOk = true;
|
||
|
emit addrecent(filename);
|
||
|
}
|
||
|
else
|
||
|
{
|
||
13 years ago
|
TQString msg = i18n("There was an error saving:\n%1\n").arg(str);
|
||
13 years ago
|
KMessageBox::error((TQWidget*)parent(), msg);
|
||
12 years ago
|
kdDebug(4640) << "TDEIconEditIcon::save - " << msg << endl;
|
||
15 years ago
|
}
|
||
|
|
||
12 years ago
|
kdDebug(4640) << "TDEIconEditIcon::save - done" << endl;
|
||
15 years ago
|
|
||
|
return savedOk;
|
||
|
}
|
||
|
|
||
|
|
||
11 years ago
|
#include "tdeicon.moc"
|