summaryrefslogtreecommitdiffstats
path: root/buildtools/autotools/addicondlg.cpp
blob: 2f1ab2929f6bb4b1dfc6201cdbfaa9f11f44ad6b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
/***************************************************************************
 *   Copyright (C) 2002 by Bernd Gehrmann                                  *
 *   bernd@tdevelop.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.                                   *
 *                                                                         *
 ***************************************************************************/

#include "addicondlg.h"

#include <tqcombobox.h>
#include <tqlabel.h>
#include <klineedit.h>
#include <kdebug.h>
#include <klocale.h>
#include <kprocess.h>
#include <kstandarddirs.h>
#include <kicontheme.h>
#include <tdeversion.h> // fix me!

#include "autolistviewitems.h"

#include "autoprojectpart.h"
#include "autoprojectwidget.h"


const char *type_map[] = {
    "app", "action", "device", "filesys", "mime"
};


const char *size_map[] = {
    "hi16", "hi22", "hi32", "hi48", "hi64", "hi128"
};


AddIconDialog::AddIconDialog(AutoProjectPart *part, AutoProjectWidget *widget,
                             SubprojectItem *spitem, TargetItem *titem,
                             TQWidget *parent, const char *name)
    : AddIconDialogBase(parent, name, true)
{
    type_combo->insertItem(i18n("Application"));
    type_combo->insertItem(i18n("Action"));
    type_combo->insertItem(i18n("Device"));
    type_combo->insertItem(i18n("File System"));
    type_combo->insertItem(i18n("MIME Type"));

    size_combo->insertItem("16");
    size_combo->insertItem("22");
    size_combo->insertItem("32");
    size_combo->insertItem("48");
    size_combo->insertItem("64");
    size_combo->insertItem("128");

    somethingChanged();

    setIcon ( SmallIcon ( "iconadd_tdevelop" ) );

    m_part = part;
    m_widget = widget;
    m_subProject = spitem;
    m_target = titem;
}


AddIconDialog::~AddIconDialog()
{}


void AddIconDialog::somethingChanged()
{
    TQString size = size_map[size_combo->currentItem()];
    TQString type = type_map[type_combo->currentItem()];
    TQString name = name_edit->text();

    filename_edit->setText(size + "-" + type + "-" + name + ".png");
}


void AddIconDialog::accept()
{
    TQString name = filename_edit->text();
    
    TQString destdir = m_subProject->subdir;
    TQString destpath = destdir + "/" + name;

    TQString size = size_combo->currentText();
    TQString unknown = KIconTheme::defaultThemeName()+ "/" + size + "x" + size + "/mimetypes/unknown.png";

    TQString templateFileName = locate("icon", unknown);
    kdDebug(9020) << "Unknown: " << unknown << ", template: " << templateFileName << endl;

    if (!templateFileName.isEmpty()) {
        TDEProcess proc;
        proc << "cp";
        proc << templateFileName;
        proc << destpath;
        proc.start(TDEProcess::DontCare);
    }
    
    FileItem *fitem = m_widget->createFileItem(name, m_subProject);
    m_target->sources.append(fitem);
    m_target->insertItem(fitem);

    m_part->startMakeCommand(destdir, TQString::fromLatin1("force-reedit"));
	
	m_widget->emitAddedFile(destpath);

    TQDialog::accept();
}

#include "addicondlg.moc"