Commits

equalsraf committed 36d444e

Fix string conversion and refactor VimWrapper::convertTo

- We neglected to properly convert several strings from Vim. The end
result is that some text shows up corrupted in those dialogs (wrong
encoding).
- Added missing string conversions for:
+ Title and message for popup dialog
+ Font names
+ Color names
+ initdir argument for the :browse command
- Additionally I ended up refactoring the VimWrapper::convertTo
to make it easier to spot this kind of issues:
1. The VimWrapper::convertFrom(char*, ...) method is
now [protected], 2 new methods were added that take
(char_u*) and (QByteArray) as arguments.
2. Replace string conversion calls in VimAction with
VimWrapper::convertFrom()
* Issue#65

Comments (0)

Files changed (4)

 GuiFont
 gui_mch_get_font(char_u *name, int giveErrorIfMissing)
 {
-	QString family = (char*)name;
+	QString family = VimWrapper::convertFrom(name);
 	QFont font;
 	font.setStyleHint(QFont::TypeWriter);
 	font.setStyleStrategy(QFont::StyleStrategy(QFont::PreferDefault | QFont::ForceIntegerMetrics) );
 		QString realname = family.section(' ', 0, -2).trimmed();
 		font.setFamily(realname);
 		font.setPointSize(size);
-	} else if ( !font.fromString((char*)name) ) {
-		font.setRawName((char*)name);
+	} else if ( !font.fromString(family) ) {
+		font.setRawName(family);
 	}
 
 	font.setBold(false);
 gui_mch_settitle(char_u *title, char_u *icon)
 {
 	if ( title != NULL ) {
-		window->setWindowTitle( VimWrapper::convertFrom((char*)title) );
+		window->setWindowTitle( VimWrapper::convertFrom(title) );
 	}
 }
 
 	type = clip_convert_selection(&str, (long_u *)&size, cbd);
 	if (type >= 0) {
 		QClipboard *clip = QApplication::clipboard();
-		clip->setText( VimWrapper::convertFrom((char *)str, size), (QClipboard::Mode)cbd->clipboardMode);
+		clip->setText( VimWrapper::convertFrom(str, size), (QClipboard::Mode)cbd->clipboardMode);
 	}
 
 	vim_free(str);
     int		len,
     int		flags)
 {
-	QString str = VimWrapper::convertFrom((char *)s, len);
+	QString str = VimWrapper::convertFrom(s, len);
 	
 	// Font
 	QFont f = vimshell->font();
 	if ( reqname == NULL ) {
 		return INVALCOLOR;
 	}
-	QColor c = vimshell->color((char*)reqname);
+	QColor c = vimshell->color(VimWrapper::convertFrom(reqname));
 	if ( c.isValid() ) {
 		return VimWrapper::toColor(c);
 	}
 	QAction *before=NULL;
 
 	if ( menu_is_popup(menu->name) ) {
-		menu->qmenu = new QMenu(VimWrapper::convertFrom((char*)menu->name), vimshell);
+		menu->qmenu = new QMenu(VimWrapper::convertFrom(menu->name), vimshell);
 	} else if ( menu_is_toolbar(menu->name) ) {
 		menu->qmenu = window->toolBar();
 	} else if ( menu->parent == NULL ) {
 			before = actions.at(idx);
 		}
 
-		QMenu *m = new QMenu(VimWrapper::convertFrom((char*)menu->name), window);
+		QMenu *m = new QMenu(VimWrapper::convertFrom(menu->name), window);
 		window->menuBar()->insertMenu( before, m);
 		menu->qmenu = m;
 	} else if ( menu->parent && menu->parent->qmenu ) {
 			before = actions.at(idx);
 		}
 
-		QMenu *m = new QMenu(VimWrapper::convertFrom((char*)menu->name), window);
+		QMenu *m = new QMenu(VimWrapper::convertFrom(menu->name), window);
 		parent->insertMenu( before, m);
 		menu->qmenu = m;
 	}
 	if ( initdir == NULL ) {
 		dir = "";
 	} else {
-		dir = (char*)initdir;
+		dir = VimWrapper::convertFrom(initdir);
 	}
 
 	window->setEnabled(false);
-	QString file = QFileDialog::getOpenFileName(window, (char*)title, dir);
+	QString file = QFileDialog::getOpenFileName(window, VimWrapper::convertFrom(title), dir);
 	window->setEnabled(true);
 	vimshell->setFocus();
 
 gui_mch_dialog(int type, char_u *title, char_u *message, char_u *buttons, int dfltbutton, char_u *textfield, int ex_cmd)
 {
 	QMessageBox msgBox(window);
-	msgBox.setText( (char*)message );
-	msgBox.setWindowTitle( (char*)title );
+	msgBox.setText( VimWrapper::convertFrom(message) );
+	msgBox.setWindowTitle( VimWrapper::convertFrom(title) );
 	
 	// Set icon
 	QMessageBox::Icon icon;
 	if ( buttons != NULL ) {
 		QStringList b_string;
 
-		b_string = VimWrapper::convertFrom((char*)buttons).split(DLG_BUTTON_SEP);
+		b_string = VimWrapper::convertFrom(buttons).split(DLG_BUTTON_SEP);
 
 		QListIterator<QString> it(b_string);
 		int bt=1;
 
 		get_tabline_label(tp, FALSE);
 		char_u *labeltext = CONVERT_TO_UTF8(NameBuff);
-		window->setTab( nr, VimWrapper::convertFrom((char*)labeltext));
+		window->setTab( nr, VimWrapper::convertFrom(labeltext));
 		CONVERT_TO_UTF8_FREE(labeltext);
 	}
 	window->removeTabs(nr);
 		return NULL;
 	}
 
-	QString name = VimWrapper::convertFrom((char*)signfile);
+	QString name = VimWrapper::convertFrom(signfile);
 	QIcon icon(name);
 
 	//

src/qt/vimaction.cpp

 			setIcon( VimWrapper::icon(iconNames.at(menu->iconidx)) );
 		}
 
-		setToolTip(QString::fromUtf8((char*) menu->strings[MENU_INDEX_TIP]));
+		setToolTip(VimWrapper::convertFrom(menu->strings[MENU_INDEX_TIP]));
 	} else {
-		setText( QString::fromUtf8((char*)menu->name) );
+		setText( VimWrapper::convertFrom(menu->name) );
 	}
 	connect(this, SIGNAL(triggered()),
 			this, SLOT(actionTriggered()));

src/qt/vimwrapper.cpp

 	}
 }
 
+QString VimWrapper::convertFrom(const QByteArray& arr)
+{
+	return convertFrom( arr.data(), arr.size());
+}
+
+QString VimWrapper::convertFrom(const char_u *s, int size)
+{
+	return convertFrom( (char*)s, size);
+}
+
 void VimWrapper::setFullscreen(bool on)
 {
 	if (on) {

src/qt/vimwrapper.h

 	static void newTab(int idx=1);
 
 	static QByteArray convertTo(const QString& s);
-	static QString convertFrom(const char *, int size=-1);
+	static QString convertFrom(const char_u *, int size=-1);
+	static QString convertFrom(const QByteArray&);
 
 
 	/**
 
 	static void setFullscreen(bool on);
 
+protected:
+	static QString convertFrom(const char *, int size=-1);
+
 private slots:
 
 	/**