summaryrefslogtreecommitdiffstats
path: root/vcs/perforce/commitdlg.cpp
blob: 6bb3c08d646b37f6e69ffb8cc3a7585eaffe7c05 (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
/***************************************************************************
 *   Copyright (C) 1999, 2000 by Bernd Gehrmann                            *
 *   bernd@kdevelop.org                                                    *
 *   Modified for perforce 2002 by Harald Fernengel <harry@kdevelop.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 "commitdlg.h"

#include <tqlayout.h>
#include <tqlabel.h>
#include <tqtextedit.h>
#include <tqpushbutton.h>
#include <tqregexp.h>
#include <kprocess.h>
#include <kapplication.h>
#include <klocale.h>
#include <klineedit.h>
#include <kmessagebox.h>
#include <kdebug.h>

#include <stdlib.h>

#include "execcommand.h"

CommitDialog::CommitDialog( TQWidget *tqparent, const char *name )
    : KDialogBase( tqparent, name, true, i18n("Perforce Submit"), Ok|Cancel|Details )
{
    TQWidget *w = new TQWidget( this, "main widget" );
    setMainWidget( w );

    edit = new TQTextEdit( w );
    TQFontMetrics fm(edit->fontMetrics());
    edit->setMinimumSize(fm.width("0")*40, fm.lineSpacing()*3);

    TQVBoxLayout *tqlayout = new TQVBoxLayout( w, 0, spacingHint() );
    TQLabel *editLabel = new TQLabel(i18n("&Enter description:"), w);
    editLabel->setBuddy(edit);
    tqlayout->addWidget(editLabel);
    tqlayout->addWidget(edit);

    w = new TQWidget( this, "details widget" );

    clientEdit = new KLineEdit( w );
    userEdit = new KLineEdit( w );
    filesBox = new KListBox( w );

    tqlayout = new TQVBoxLayout( w, 0, spacingHint() );
    TQLabel *clientLabel = new TQLabel(i18n("C&lient:"), w);
    clientLabel->setBuddy(clientEdit);
    tqlayout->addWidget(clientLabel);
    tqlayout->addWidget( clientEdit );
    TQLabel *userLabel = new TQLabel(i18n("&User:"), w);
    userLabel->setBuddy(userEdit);
    tqlayout->addWidget( userLabel );
    tqlayout->addWidget( userEdit );
    TQLabel *filesLabel = new TQLabel(i18n("&File(s):"), w);
    filesLabel->setBuddy(filesBox);
    tqlayout->addWidget( filesLabel );
    tqlayout->addWidget( filesBox );

    setDetailsWidget( w );
    autoGuess();
    edit->setFocus();
}

CommitDialog::~CommitDialog()
{
}

void CommitDialog::autoGuess()
{
    char *cenv;

    cenv = getenv( "P4USER" );
    if ( cenv ) {
        setUser( TQString::fromLocal8Bit( cenv ) );
    }

    cenv = getenv( "P4CLIENT" );
    if ( cenv ) {
        setClient( TQString::fromLocal8Bit( cenv ) );
    }
}

void CommitDialog::setFiles( const TQStringList& lst )
{
    filesBox->clear();
    setDepotFiles( lst );
}

void CommitDialog::setDepotFiles( const TQStringList& lst )
{
    TQStringList args;

    args << "files";
    for ( TQStringList::ConstIterator it = lst.begin(); it != lst.end(); ++it ) {
        args << (*it);
    }

    ExecCommand* cmd = new ExecCommand( "p4", args, TQString(), TQStringList(), TQT_TQOBJECT(this) );
    connect( cmd, TQT_SIGNAL(finished( const TQString&, const TQString& )),
	     this, TQT_SLOT(getFilesFinished( const TQString&, const TQString& )) );
}

void CommitDialog::getFilesFinished( const TQString& out, const TQString& /* err */ )
{
    TQStringList lst = TQStringList::split( TQChar('\n'), out );
    for ( TQStringList::ConstIterator it = lst.begin(); it != lst.end(); ++it ) {
        int pos = (*it).find( TQChar('#') );
        if ( pos > 1 && (*it).startsWith( "//" ) ) {
            filesBox->insertItem( (*it).left( pos ) );
        }
    }
}

TQString CommitDialog::changeList() const
{
    TQString lst;

    lst += "Change: new\n"
           "Client: " + client() + "\n"
           "User: " + user() + "\n"
           "tqStatus: new\n"
           "Description:\n        ";

    lst += logMessage().replace(TQRegExp("\n"), "\n        ") + "\n\n";

    lst += "Files:\n";

    for ( uint i = 0; i < filesBox->count(); ++i ) {
        lst += "       " + filesBox->text( i ) + "\n";
    }

    return lst;
}

void CommitDialog::accept()
{
    if ( client().isEmpty() ) {
        setDetails( true );
        KMessageBox::error( this, i18n("Please enter the P4 client name.") );
        clientEdit->setFocus();
    } else if ( user().isEmpty() ) {
        setDetails( true );
        KMessageBox::error( this, i18n("Please enter the P4 user.") );
        userEdit->setFocus();
    } else if ( filesBox->count() == 0 ) {
        setDetails( true );
        KMessageBox::error( this, i18n("The changelist does not contain any files.") );
    } else {
        KDialogBase::accept();
    }
}

#include "commitdlg.moc"