summaryrefslogtreecommitdiffstats
path: root/buildtools/autotools/autolistviewitems.cpp
blob: 3fb0bffd5d5309d0ad4618cffa7d57e64b1cc010 (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
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
/***************************************************************************
*   Copyright (C) 2001-2002 by Bernd Gehrmann                             *
*   bernd@kdevelop.org                                                    *
*                                                                         *
*   Copyright (C) 2002 by Victor Rder                                    *
*   victor_roeder@gmx.de                                                  *
*                                                                         *
*   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 <tqpainter.h>
#include <tqinputdialog.h>
#include <tqregexp.h>

#include <kiconloader.h>
#include "misc.h"
#include "autolistviewitems.h"
#include "autoprojectpart.h"
#include "autoprojectwidget.h"
#include "autodetailsview.h"

/**
* Class ProjectItem
*/

ProjectItem::ProjectItem( Type type, TQListView *tqparent, const TQString &text )
		: TQListViewItem( tqparent, text ), typ( type )
{
	bld = false;
}


ProjectItem::ProjectItem( Type type, ProjectItem *tqparent, const TQString &text )
		: TQListViewItem( tqparent, text ), typ( type )
{
	bld = false;
}


void ProjectItem::paintCell( TQPainter *p, const TQColorGroup &cg,
                             int column, int width, int tqalignment )
{
	if ( isBold() )
	{
		TQFont font( p->font() );
		font.setBold( true );
		p->setFont( font );
	}
	TQListViewItem::paintCell( p, cg, column, width, tqalignment );
}


/**
* Class SubprojectItem
*/

SubprojectItem::SubprojectItem( TQListView *tqparent, const TQString &text )
		: ProjectItem( Subproject, tqparent, text )
{
	init();
}


SubprojectItem::SubprojectItem( SubprojectItem *tqparent, const TQString &text )
		: ProjectItem( Subproject, tqparent, text )
{
	init();
}


void SubprojectItem::init()
{
	targets.setAutoDelete( true );
	setPixmap( 0, SmallIcon( "folder" ) );
}


TQString SubprojectItem::relativePath()
{
    TQString relpath = subdir;

    SubprojectItem *it = this;
    while ( (it= dynamic_cast<SubprojectItem*>(it->tqparent())) )
    {
        relpath.prepend(it->subdir + "/");
    }
    relpath.remove(0, 2);

    return relpath;
}


/**
* Class TargetItem
*/

TargetItem::TargetItem( TQListView *lv, bool group, const TQString &text )
		: ProjectItem( Target, lv, text )
{
	sources.setAutoDelete( true );
	setPixmap( 0, group ? SmallIcon( "tar" ) : SmallIcon( "binary" ) );
}


/**
* Class FileItem
*/

FileItem::FileItem( TQListView *lv, const TQString &text, bool set_is_subst )
		: ProjectItem( File, lv, text ) , is_subst(set_is_subst)
{
	if(!is_subst)
	{
		setPixmap( 0, SmallIcon( "document" ) );
	}
	else
	{
		setPixmap( 0, SmallIcon( "variablenew" ) );
	}
}


void FileItem::changeSubstitution()
{
if(!is_subst)
return;

	bool ok;
	TQString text = TQInputDialog::getText(
	                   i18n("Edit Substitution"), i18n("Substitution:"), TQLineEdit::Normal,
	                   name, &ok );
	if ( ok && !text.isEmpty() )
	{
		// user entered something and pressed OK
		TQString new_name = text;
		if(new_name == name)
			return;
		setText(0,new_name);
		changeMakefileEntry(new_name);
		name = new_name;
	}
	else
	{
		// user entered nothing or pressed Cancel

	}
}

void FileItem::changeMakefileEntry(const TQString& new_name)
{
	TargetItem* target = dynamic_cast<TargetItem*>(tqparent());

	TQMap<TQString,TQString> replaceMap;

	TQString canontargetname = AutoProjectTool::canonicalize(target->name);
	TQString varname;
	if( target->primary == "PROGRAMS" || target->primary == "LIBRARIES" || target->primary == "LTLIBRARIES" )
		varname = canontargetname + "_SOURCES";
	else
		varname = target->prefix + "_" + target->primary;
	if( AutoDetailsView* lv = dynamic_cast<AutoDetailsView*>(listView()) )
	{
 		if ( SubprojectItem* subProject = lv->m_part->m_widget->selectedSubproject() )
		{
			TQStringList sources = TQStringList::split(TQRegExp("[ \t\n]"), subProject->variables[varname]);
			TQStringList::iterator it = sources.tqfind(name);
			(*it) = new_name;
			subProject->variables[varname] = sources.join(" ");
			replaceMap.insert(varname, subProject->variables[varname]);
		
			AutoProjectTool::addToMakefileam(subProject->path + "/Makefile.am", replaceMap);
		
			if(new_name == "")
				target->sources.remove(this);
		}
	}
}